From 5ca10fc248fe8a5362c8694bf4c37b28a0d4c8a3 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 12 Jan 2014 16:38:34 -0700 Subject: [PATCH] Less hard-coded NSFW boards Let's let 4chan tell us if a board is NSFW or not. --- builds/appchan-x.user.js | 32 ++++++++++++++------------------ builds/crx/script.js | 32 ++++++++++++++------------------ src/General/Main.coffee | 11 ++++++----- src/General/Navigate.coffee | 2 +- src/General/Settings.coffee | 2 +- src/Monitoring/Favicon.coffee | 8 -------- 6 files changed, 36 insertions(+), 51 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 2f3f57cb5..51f68ee87 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -10965,15 +10965,6 @@ Favicon = { init: function() { - var href; - Favicon.el = $('link[rel="shortcut icon"]', d.head); - Favicon.el.type = 'image/x-icon'; - href = Favicon.el.href; - Favicon.SFW = /ws\.ico$/.test(href); - Favicon["default"] = href; - return Favicon["switch"](); - }, - "switch": function() { var f, funreadDeadY, t, _ref; t = 'data:image/png;base64,'; f = Favicon; @@ -16533,7 +16524,7 @@ return this.nextElementSibling.innerHTML = funk(FileInfo, data); }, favicon: function() { - Favicon["switch"](); + Favicon.init(); if (g.VIEW === 'thread' && Conf['Unread Favicon']) { Unread.update(); } @@ -17189,8 +17180,13 @@ }); }, initFeatures: function() { - var err, feature, name, _i, _len, _ref, _ref1, _ref2, _ref3; - g.TYPE = (_ref = g.BOARD.ID) === 'b' || _ref === 'd' || _ref === 'e' || _ref === 'gif' || _ref === 'h' || _ref === 'hc' || _ref === 'hm' || _ref === 'hr' || _ref === 'pol' || _ref === 'r' || _ref === 'r9k' || _ref === 'rs' || _ref === 's' || _ref === 's4s' || _ref === 'soc' || _ref === 't' || _ref === 'u' || _ref === 'y' ? 'nsfw' : 'sfw'; + var err, feature, href, name, _i, _len, _ref, _ref1, _ref2; + Favicon.el = $('link[rel="shortcut icon"]', d.head); + Favicon.el.type = 'image/x-icon'; + href = Favicon.el.href; + Favicon.SFW = /ws\.ico$/.test(href); + Favicon["default"] = href; + g.TYPE = Favicon.SFW ? 'sfw' : 'nsfw'; $.extend(Themes, Conf["userThemes"]); $.extend(Mascots, Conf["userMascots"]); if (Conf["NSFW/SFW Mascots"]) { @@ -17201,7 +17197,7 @@ if (Conf["NSFW/SFW Themes"]) { Conf["theme"] = Conf["theme_" + g.TYPE]; } - if ((_ref1 = g.BOARD.ID) === 'z' || _ref1 === 'fk') { + if ((_ref = g.BOARD.ID) === 'z' || _ref === 'fk') { return Style.init(); } switch (location.hostname) { @@ -17219,8 +17215,8 @@ return; case 'i.4cdn.org': $.ready(function() { - var URL, pathname, _ref2; - if (Conf['404 Redirect'] && ((_ref2 = d.title) === '4chan - Temporarily Offline' || _ref2 === '4chan - 404 Not Found')) { + var URL, pathname, _ref1; + if (Conf['404 Redirect'] && ((_ref1 = d.title) === '4chan - Temporarily Offline' || _ref1 === '4chan - 404 Not Found')) { Redirect.init(); pathname = location.pathname.split('/'); URL = Redirect.to('file', { @@ -17234,9 +17230,9 @@ }); return; } - _ref2 = Main.features; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - _ref3 = _ref2[_i], name = _ref3[0], feature = _ref3[1]; + _ref1 = Main.features; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + _ref2 = _ref1[_i], name = _ref2[0], feature = _ref2[1]; try { feature.init(); } catch (_error) { diff --git a/builds/crx/script.js b/builds/crx/script.js index b8cfe5bab..98fb2ab11 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -10949,15 +10949,6 @@ Favicon = { init: function() { - var href; - Favicon.el = $('link[rel="shortcut icon"]', d.head); - Favicon.el.type = 'image/x-icon'; - href = Favicon.el.href; - Favicon.SFW = /ws\.ico$/.test(href); - Favicon["default"] = href; - return Favicon["switch"](); - }, - "switch": function() { var f, funreadDeadY, t, _ref; t = 'data:image/png;base64,'; f = Favicon; @@ -16527,7 +16518,7 @@ return this.nextElementSibling.innerHTML = funk(FileInfo, data); }, favicon: function() { - Favicon["switch"](); + Favicon.init(); if (g.VIEW === 'thread' && Conf['Unread Favicon']) { Unread.update(); } @@ -17177,8 +17168,13 @@ }); }, initFeatures: function() { - var err, feature, name, _i, _len, _ref, _ref1, _ref2, _ref3; - g.TYPE = (_ref = g.BOARD.ID) === 'b' || _ref === 'd' || _ref === 'e' || _ref === 'gif' || _ref === 'h' || _ref === 'hc' || _ref === 'hm' || _ref === 'hr' || _ref === 'pol' || _ref === 'r' || _ref === 'r9k' || _ref === 'rs' || _ref === 's' || _ref === 's4s' || _ref === 'soc' || _ref === 't' || _ref === 'u' || _ref === 'y' ? 'nsfw' : 'sfw'; + var err, feature, href, name, _i, _len, _ref, _ref1, _ref2; + Favicon.el = $('link[rel="shortcut icon"]', d.head); + Favicon.el.type = 'image/x-icon'; + href = Favicon.el.href; + Favicon.SFW = /ws\.ico$/.test(href); + Favicon["default"] = href; + g.TYPE = Favicon.SFW ? 'sfw' : 'nsfw'; $.extend(Themes, Conf["userThemes"]); $.extend(Mascots, Conf["userMascots"]); if (Conf["NSFW/SFW Mascots"]) { @@ -17189,7 +17185,7 @@ if (Conf["NSFW/SFW Themes"]) { Conf["theme"] = Conf["theme_" + g.TYPE]; } - if ((_ref1 = g.BOARD.ID) === 'z' || _ref1 === 'fk') { + if ((_ref = g.BOARD.ID) === 'z' || _ref === 'fk') { return Style.init(); } switch (location.hostname) { @@ -17207,8 +17203,8 @@ return; case 'i.4cdn.org': $.ready(function() { - var URL, pathname, _ref2; - if (Conf['404 Redirect'] && ((_ref2 = d.title) === '4chan - Temporarily Offline' || _ref2 === '4chan - 404 Not Found')) { + var URL, pathname, _ref1; + if (Conf['404 Redirect'] && ((_ref1 = d.title) === '4chan - Temporarily Offline' || _ref1 === '4chan - 404 Not Found')) { Redirect.init(); pathname = location.pathname.split('/'); URL = Redirect.to('file', { @@ -17222,9 +17218,9 @@ }); return; } - _ref2 = Main.features; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - _ref3 = _ref2[_i], name = _ref3[0], feature = _ref3[1]; + _ref1 = Main.features; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + _ref2 = _ref1[_i], name = _ref2[0], feature = _ref2[1]; try { feature.init(); } catch (_error) { diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 427c95136..7b94f3073 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -48,11 +48,12 @@ Main = initFeatures: -> # Check if the current board we're on is SFW or not, so we can handle options that need to know that. - g.TYPE = - if g.BOARD.ID in ['b', 'd', 'e', 'gif', 'h', 'hc', 'hm', 'hr', 'pol', 'r', 'r9k', 'rs', 's', 's4s', 'soc', 't', 'u', 'y'] - 'nsfw' - else - 'sfw' + Favicon.el = $ 'link[rel="shortcut icon"]', d.head + Favicon.el.type = 'image/x-icon' + {href} = Favicon.el + Favicon.SFW = /ws\.ico$/.test href + Favicon.default = href + g.TYPE = if Favicon.SFW then 'sfw' else 'nsfw' $.extend Themes, Conf["userThemes"] $.extend Mascots, Conf["userMascots"] diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 37bfc18fa..8a36fbdad 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -156,7 +156,7 @@ Navigate = Favicon.SFW = sfw Favicon.el.href = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico" $.add d.head, Favicon.el # Changing the href alone doesn't update the icon on Firefox - Favicon.switch() + Favicon.init() mainStyleSheet.href = newStyleSheet.href diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 58472f805..9679c399a 100755 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -411,7 +411,7 @@ Settings = @nextElementSibling.innerHTML = funk FileInfo, data favicon: -> - Favicon.switch() + Favicon.init() Unread.update() if g.VIEW is 'thread' and Conf['Unread Favicon'] $.id('favicon-preview').innerHTML = """ diff --git a/src/Monitoring/Favicon.coffee b/src/Monitoring/Favicon.coffee index 157ee1dda..e22d11540 100755 --- a/src/Monitoring/Favicon.coffee +++ b/src/Monitoring/Favicon.coffee @@ -1,13 +1,5 @@ Favicon = init: -> - Favicon.el = $ 'link[rel="shortcut icon"]', d.head - Favicon.el.type = 'image/x-icon' - {href} = Favicon.el - Favicon.SFW = /ws\.ico$/.test href - Favicon.default = href - Favicon.switch() - - switch: -> t = 'data:image/png;base64,' f = Favicon [f.unreadDead, funreadDeadY, f.unreadSFW, f.unreadSFWY, f.unreadNSFW, f.unreadNSFWY] = switch Conf['favicon']