diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 07329ced2..39ae3bd2f 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -10370,11 +10370,10 @@ if (!Conf['Catalog Links']) { return; } - el = $.el('label', { + CatalogLinks.el = el = $.el('label', { id: 'toggleCatalog', href: 'javascript:;', - innerHTML: " Catalog Links", - title: "Turn catalog links " + (Conf['Header catalog links'] ? 'off' : 'on') + "." + innerHTML: " Catalog Links" }); input = $('input', el); $.on(input, 'change', this.toggle); @@ -10389,33 +10388,88 @@ }); }, toggle: function() { - var useCatalog; - $.event('CloseMenu'); - $.set('Header catalog links', useCatalog = this.checked); - return CatalogLinks.set(useCatalog); + $.set('Header catalog links', this.checked); + return CatalogLinks.set(this.checked); }, set: function(useCatalog) { - var a, board, path, _i, _len, _ref; + var a, board, generateURL, path, _i, _len, _ref; path = useCatalog ? 'catalog' : ''; - _ref = $$("#board-list a:not(.catalog),\n#boardNavDesktopFoot a"); + generateURL = useCatalog && Conf['External Catalog'] ? CatalogLinks.external : function(board) { + return a.href = "/" + board + "/" + path; + }; + _ref = $$("#board-list a:not(.catalog), #boardNavDesktopFoot a"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; - board = a.pathname.split('/')[1]; - if (['f', 'status', '4chan'].contains(board) || !board) { + if (!['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'].contains(a.hostname) || !(board = a.pathname.split('/')[1]) || ['f', 'status', '4chan'].contains(board)) { continue; } - if (Conf['External Catalog']) { - a.href = useCatalog ? CatalogLinks.external(board) : "/" + board + "/"; - } else { - a.pathname = "/" + board + "/" + path; - } + a.href = generateURL(board); } - return this.title = "Turn catalog links " + (useCatalog ? 'off' : 'on') + "."; + return CatalogLinks.el.title = "Turn catalog links " + (useCatalog ? 'off' : 'on') + "."; }, external: function(board) { - return (['a', 'c', 'g', 'co', 'k', 'm', 'o', 'p', 'v', 'vg', 'w', 'cm', '3', 'adv', 'an', 'cgl', 'ck', 'diy', 'fa', 'fit', 'int', 'jp', 'mlp', 'lit', 'mu', 'n', 'po', 'sci', 'toy', 'trv', 'tv', 'vp', 'x', 'q'].contains(board) ? "http://catalog.neet.tv/" + board : ['d', 'e', 'gif', 'h', 'hr', 'hc', 'r9k', 's', 'pol', 'soc', 'u', 'i', 'ic', 'hm', 'r', 'w', 'wg', 'wsg', 't', 'y'].contains(board) ? "http://4index.gropes.us/" + board : "/" + board + "/catalog"); + switch (board) { + case 'a': + case 'c': + case 'g': + case 'co': + case 'k': + case 'm': + case 'o': + case 'p': + case 'v': + case 'vg': + case 'w': + case 'cm': + case '3': + case 'adv': + case 'an': + case 'cgl': + case 'ck': + case 'diy': + case 'fa': + case 'fit': + case 'int': + case 'jp': + case 'mlp': + case 'lit': + case 'mu': + case 'n': + case 'po': + case 'sci': + case 'toy': + case 'trv': + case 'tv': + case 'vp': + case 'x': + case 'q': + return "http://catalog.neet.tv/" + board; + case 'd': + case 'e': + case 'gif': + case 'h': + case 'hr': + case 'hc': + case 'r9k': + case 's': + case 'pol': + case 'soc': + case 'u': + case 'i': + case 'ic': + case 'hm': + case 'r': + case 'w': + case 'wg': + case 'wsg': + case 't': + case 'y': + return "http://4index.gropes.us/" + board; + default: + return "/" + board + "/catalog"; + } } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 5afce40fe..377c1155f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -10361,11 +10361,10 @@ if (!Conf['Catalog Links']) { return; } - el = $.el('label', { + CatalogLinks.el = el = $.el('label', { id: 'toggleCatalog', href: 'javascript:;', - innerHTML: " Catalog Links", - title: "Turn catalog links " + (Conf['Header catalog links'] ? 'off' : 'on') + "." + innerHTML: " Catalog Links" }); input = $('input', el); $.on(input, 'change', this.toggle); @@ -10380,33 +10379,88 @@ }); }, toggle: function() { - var useCatalog; - $.event('CloseMenu'); - $.set('Header catalog links', useCatalog = this.checked); - return CatalogLinks.set(useCatalog); + $.set('Header catalog links', this.checked); + return CatalogLinks.set(this.checked); }, set: function(useCatalog) { - var a, board, path, _i, _len, _ref; + var a, board, generateURL, path, _i, _len, _ref; path = useCatalog ? 'catalog' : ''; - _ref = $$("#board-list a:not(.catalog),\n#boardNavDesktopFoot a"); + generateURL = useCatalog && Conf['External Catalog'] ? CatalogLinks.external : function(board) { + return a.href = "/" + board + "/" + path; + }; + _ref = $$("#board-list a:not(.catalog), #boardNavDesktopFoot a"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; - board = a.pathname.split('/')[1]; - if (['f', 'status', '4chan'].contains(board) || !board) { + if (!['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'].contains(a.hostname) || !(board = a.pathname.split('/')[1]) || ['f', 'status', '4chan'].contains(board)) { continue; } - if (Conf['External Catalog']) { - a.href = useCatalog ? CatalogLinks.external(board) : "/" + board + "/"; - } else { - a.pathname = "/" + board + "/" + path; - } + a.href = generateURL(board); } - return this.title = "Turn catalog links " + (useCatalog ? 'off' : 'on') + "."; + return CatalogLinks.el.title = "Turn catalog links " + (useCatalog ? 'off' : 'on') + "."; }, external: function(board) { - return (['a', 'c', 'g', 'co', 'k', 'm', 'o', 'p', 'v', 'vg', 'w', 'cm', '3', 'adv', 'an', 'cgl', 'ck', 'diy', 'fa', 'fit', 'int', 'jp', 'mlp', 'lit', 'mu', 'n', 'po', 'sci', 'toy', 'trv', 'tv', 'vp', 'x', 'q'].contains(board) ? "http://catalog.neet.tv/" + board : ['d', 'e', 'gif', 'h', 'hr', 'hc', 'r9k', 's', 'pol', 'soc', 'u', 'i', 'ic', 'hm', 'r', 'w', 'wg', 'wsg', 't', 'y'].contains(board) ? "http://4index.gropes.us/" + board : "/" + board + "/catalog"); + switch (board) { + case 'a': + case 'c': + case 'g': + case 'co': + case 'k': + case 'm': + case 'o': + case 'p': + case 'v': + case 'vg': + case 'w': + case 'cm': + case '3': + case 'adv': + case 'an': + case 'cgl': + case 'ck': + case 'diy': + case 'fa': + case 'fit': + case 'int': + case 'jp': + case 'mlp': + case 'lit': + case 'mu': + case 'n': + case 'po': + case 'sci': + case 'toy': + case 'trv': + case 'tv': + case 'vp': + case 'x': + case 'q': + return "http://catalog.neet.tv/" + board; + case 'd': + case 'e': + case 'gif': + case 'h': + case 'hr': + case 'hc': + case 'r9k': + case 's': + case 'pol': + case 'soc': + case 'u': + case 'i': + case 'ic': + case 'hm': + case 'r': + case 'w': + case 'wg': + case 'wsg': + case 't': + case 'y': + return "http://4index.gropes.us/" + board; + default: + return "/" + board + "/catalog"; + } } }; diff --git a/src/Miscellaneous/CatalogLinks.coffee b/src/Miscellaneous/CatalogLinks.coffee index 48a678874..869fecc1a 100755 --- a/src/Miscellaneous/CatalogLinks.coffee +++ b/src/Miscellaneous/CatalogLinks.coffee @@ -1,11 +1,10 @@ CatalogLinks = init: -> return unless Conf['Catalog Links'] - el = $.el 'label', + CatalogLinks.el = el = $.el 'label', id: 'toggleCatalog' href: 'javascript:;' innerHTML: " Catalog Links" - title: "Turn catalog links #{if Conf['Header catalog links'] then 'off' else 'on'}." input = $ 'input', el $.on input, 'change', @toggle @@ -22,32 +21,33 @@ CatalogLinks = toggle: -> $.event 'CloseMenu' - $.set 'Header catalog links', useCatalog = @checked - CatalogLinks.set useCatalog + $.set 'Header catalog links', @checked + CatalogLinks.set @checked set: (useCatalog) -> path = if useCatalog then 'catalog' else '' - for a in $$ """ - #board-list a:not(.catalog), - #boardNavDesktopFoot a - """ - board = a.pathname.split('/')[1] - continue if ['f', 'status', '4chan'].contains(board) or !board - if Conf['External Catalog'] - a.href = if useCatalog - CatalogLinks.external board - else - "/#{board}/" - else - a.pathname = "/#{board}/#{path}" - @title = "Turn catalog links #{if useCatalog then 'off' else 'on'}." + + generateURL = if useCatalog and Conf['External Catalog'] + CatalogLinks.external + else + (board) -> a.href = "/#{board}/#{path}" + + for a in $$ """#board-list a:not(.catalog), #boardNavDesktopFoot a""" + continue if !['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'].contains(a.hostname) or + !(board = a.pathname.split('/')[1]) or + ['f', 'status', '4chan'].contains board + + # Href is easier than pathname because then we don't have + # conditions where External Catalog has been disabled between switches. + a.href = generateURL board + + CatalogLinks.el.title = "Turn catalog links #{if useCatalog then 'off' else 'on'}." external: (board) -> - return ( - if ['a', 'c', 'g', 'co', 'k', 'm', 'o', 'p', 'v', 'vg', 'w', 'cm', '3', 'adv', 'an', 'cgl', 'ck', 'diy', 'fa', 'fit', 'int', 'jp', 'mlp', 'lit', 'mu', 'n', 'po', 'sci', 'toy', 'trv', 'tv', 'vp', 'x', 'q'].contains board + switch board + when 'a', 'c', 'g', 'co', 'k', 'm', 'o', 'p', 'v', 'vg', 'w', 'cm', '3', 'adv', 'an', 'cgl', 'ck', 'diy', 'fa', 'fit', 'int', 'jp', 'mlp', 'lit', 'mu', 'n', 'po', 'sci', 'toy', 'trv', 'tv', 'vp', 'x', 'q' "http://catalog.neet.tv/#{board}" - else if ['d', 'e', 'gif', 'h', 'hr', 'hc', 'r9k', 's', 'pol', 'soc', 'u', 'i', 'ic', 'hm', 'r', 'w', 'wg', 'wsg', 't', 'y'].contains board + when 'd', 'e', 'gif', 'h', 'hr', 'hc', 'r9k', 's', 'pol', 'soc', 'u', 'i', 'ic', 'hm', 'r', 'w', 'wg', 'wsg', 't', 'y' "http://4index.gropes.us/#{board}" else - "/#{board}/catalog" - ) \ No newline at end of file + "/#{board}/catalog" \ No newline at end of file