diff --git a/4chan_x.user.js b/4chan_x.user.js
index dd78c56d6..31f1bf014 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -5189,60 +5189,45 @@
CatalogLinks = {
init: function() {
- var el, i, nav, _i, _len, _ref;
+ var clone, el, nav, _i, _len, _ref;
el = $.el('span', {
- innerHTML: "[Catalog " + (!g.CATALOG ? 'On' : 'Off') + "]",
- id: 'toggleCatalog'
+ className: 'toggleCatalog',
+ innerHTML: '[]'
});
_ref = ['boardNavDesktop', 'boardNavDesktopFoot'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
nav = _ref[_i];
- $.on(el.firstElementChild, 'click', this.toggle);
- $.add($.id(nav), el);
- el = $.el('span', {
- innerHTML: el.innerHTML,
- id: 'toggleCatalogFoot'
- });
- }
- if ($.get('CatalogIsToggled')) {
- i = g.CATALOG ? 0 : 1;
- while (i < 2) {
- this.toggle();
- i++;
- }
- return;
- }
- if (g.CATALOG) {
- return this.toggle();
+ clone = el.cloneNode(true);
+ $.on(clone.firstElementChild, 'click', this.toggle);
+ $.add($.id(nav), clone);
}
+ return this.toggle(true);
},
- toggle: function() {
- var a, el, isDead, nav, split, _i, _len, _ref;
+ toggle: function(onLoad) {
+ var a, board, nav, root, useCatalog, _i, _j, _len, _len1, _ref, _ref1;
+ if (onLoad === true) {
+ useCatalog = $.get('CatalogIsToggled', g.CATALOG);
+ } else {
+ useCatalog = this.textContent === 'Catalog Off';
+ $.set('CatalogIsToggled', useCatalog);
+ }
_ref = ['boardNavDesktop', 'boardNavDesktopFoot'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
nav = _ref[_i];
- a = $.id(nav).firstElementChild;
- while (a.href && (split = a.href.split('/'))) {
- if (!/^rs|status/.test(split[2])) {
- if ((isDead = split[3] === 'f') && g.CATALOG || split[4] === 'catalog') {
- a.href = a.href.replace(/catalog$/, '');
- a.title = a.title.replace(/\ -\ Catalog$/, '');
- } else if (!isDead) {
- a.href += 'catalog';
- a.title += ' - Catalog';
- }
+ root = $.id(nav);
+ _ref1 = $$('a[href*="boards.4chan.org"]', root);
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ a = _ref1[_j];
+ board = a.pathname.split('/')[1];
+ if (board === 'f') {
+ a.pathname = '/f/';
+ continue;
}
- a = a.nextElementSibling;
- }
- if (/On$/.test((el = a.parentNode.lastChild.firstElementChild).textContent)) {
- el.textContent = 'Catalog Off';
- el.title = 'Turn Catalog Links off.';
- $.set('CatalogIsToggled', true);
- } else {
- el.textContent = 'Catalog On';
- el.title = 'Turn Catalog Links on.';
- $["delete"]('CatalogIsToggled');
+ a.pathname = "/" + board + "/" + (useCatalog ? 'catalog' : '');
}
+ a = $('.toggleCatalog', root).firstElementChild;
+ a.textContent = "Catalog " + (useCatalog ? 'On' : 'Off');
+ a.title = "Turn catalog links " + (useCatalog ? 'off' : 'on') + ".";
}
}
};
diff --git a/script.coffee b/script.coffee
index a6e2e0a0a..405328d7e 100644
--- a/script.coffee
+++ b/script.coffee
@@ -4197,43 +4197,36 @@ ImageExpand =
CatalogLinks =
init: ->
el = $.el 'span',
- innerHTML:
- "[Catalog #{unless g.CATALOG then 'On' else 'Off'}]"
- id: 'toggleCatalog'
+ className: 'toggleCatalog'
+ innerHTML: '[]'
for nav in ['boardNavDesktop', 'boardNavDesktopFoot']
- $.on el.firstElementChild, 'click', @toggle
- $.add $.id(nav), el
- el = $.el 'span', innerHTML: el.innerHTML, id: 'toggleCatalogFoot'
+ clone = el.cloneNode true
+ $.on clone.firstElementChild, 'click', @toggle
+ $.add $.id(nav), clone
- if $.get 'CatalogIsToggled'
- i = if g.CATALOG then 0 else 1
- while i < 2
- @toggle()
- i++
- return
- @toggle() if g.CATALOG
+ # Set links on load.
+ @toggle true
+
+ toggle: (onLoad) ->
+ if onLoad is true
+ useCatalog = $.get 'CatalogIsToggled', g.CATALOG
+ else
+ useCatalog = @textContent is 'Catalog Off'
+ $.set 'CatalogIsToggled', useCatalog
- toggle: ->
for nav in ['boardNavDesktop', 'boardNavDesktopFoot']
- a = $.id(nav).firstElementChild
- while a.href and split = a.href.split '/'
- unless /^rs|status/.test split[2]
- if (isDead = split[3] is 'f') and g.CATALOG or split[4] is 'catalog'
- a.href = a.href.replace /catalog$/, ''
- a.title = a.title.replace /\ -\ Catalog$/, ''
- else if not isDead
- a.href += 'catalog'
- a.title += ' - Catalog'
- a = a.nextElementSibling
+ root = $.id nav
+ for a in $$ 'a[href*="boards.4chan.org"]', root
+ board = a.pathname.split('/')[1]
+ if board is 'f'
+ # 4chan links to /f/'s catalog even if it doesn't have one.
+ a.pathname = '/f/'
+ continue
+ a.pathname = "/#{board}/#{if useCatalog then 'catalog' else ''}"
- if /On$/.test (el = a.parentNode.lastChild.firstElementChild).textContent
- el.textContent = 'Catalog Off'
- el.title = 'Turn Catalog Links off.'
- $.set 'CatalogIsToggled', true
- else
- el.textContent = 'Catalog On'
- el.title = 'Turn Catalog Links on.'
- $.delete 'CatalogIsToggled'
+ a = $('.toggleCatalog', root).firstElementChild
+ a.textContent = "Catalog #{if useCatalog then 'On' else 'Off'}"
+ a.title = "Turn catalog links #{if useCatalog then 'off' else 'on'}."
return
Main =