Faster Catalog Links code

Ours is based on @ihavenoface's old catalog code, not @MayhemYDG's,
so we don't particularly benefit from advancements in his code, per
se, without rechecking and validating the quality of our own. This
happens to be a case where we were stuck in an inefficient paradigm
and never revisited.

We now appear much closer to Mayhem's code, but are still mostly
absent from being merged into the rest of the Header code. Whether
we decide to merge or not should probably be discussed at some
point.
This commit is contained in:
Zixaphir 2013-12-18 16:40:31 -07:00
parent 2fa6e063ef
commit 3b1340433e
3 changed files with 167 additions and 59 deletions

View File

@ -10370,11 +10370,10 @@
if (!Conf['Catalog Links']) {
return;
}
el = $.el('label', {
CatalogLinks.el = el = $.el('label', {
id: 'toggleCatalog',
href: 'javascript:;',
innerHTML: "<input type=checkbox " + (Conf['Header catalog links'] ? 'checked' : '') + "> Catalog Links",
title: "Turn catalog links " + (Conf['Header catalog links'] ? 'off' : 'on') + "."
innerHTML: "<input type=checkbox " + (Conf['Header catalog links'] ? 'checked' : '') + "> 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";
}
}
};

View File

@ -10361,11 +10361,10 @@
if (!Conf['Catalog Links']) {
return;
}
el = $.el('label', {
CatalogLinks.el = el = $.el('label', {
id: 'toggleCatalog',
href: 'javascript:;',
innerHTML: "<input type=checkbox " + (Conf['Header catalog links'] ? 'checked' : '') + "> Catalog Links",
title: "Turn catalog links " + (Conf['Header catalog links'] ? 'off' : 'on') + "."
innerHTML: "<input type=checkbox " + (Conf['Header catalog links'] ? 'checked' : '') + "> 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";
}
}
};

View File

@ -1,11 +1,10 @@
CatalogLinks =
init: ->
return unless Conf['Catalog Links']
el = $.el 'label',
CatalogLinks.el = el = $.el 'label',
id: 'toggleCatalog'
href: 'javascript:;'
innerHTML: "<input type=checkbox #{if Conf['Header catalog links'] then 'checked' else ''}> 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"
)
"/#{board}/catalog"