From 8ba48981589775316f8e643d9aa502969ace0043 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 31 Jul 2014 14:04:15 -0700 Subject: [PATCH] Fix an issue where catalog links were affecting external links #773 --- LICENSE | 2 +- builds/appchan-x.user.js | 26 ++++++++++++++------------ builds/crx/script.js | 26 ++++++++++++++------------ src/General/Header.coffee | 21 +++++++++++---------- src/Miscellaneous/CatalogLinks.coffee | 3 ++- 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/LICENSE b/LICENSE index 0dd018107..ed5da9c31 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* appchan x - Version 2.9.32 - 2014-07-30 +* appchan x - Version 2.9.32 - 2014-07-31 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index d01773b92..dab841bfe 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -28,7 +28,7 @@ // ==/UserScript== /* -* appchan x - Version 2.9.32 - 2014-07-30 +* appchan x - Version 2.9.32 - 2014-07-31 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -4309,29 +4309,31 @@ as = $$('#full-board-list a[title]', Header.boardList); re = /[\w@]+(-(all|title|replace|full|archive|(mode|sort|text|url):"[^"]+"(\,"[^"]+[^"]")?))*|[^\w@]+/g; nodes = text.match(re).map(function(t) { - var a, board, boardID, href, m, type, _i, _len; + var a, board, boardID, href, m, match, type, url, _i, _len; if (/^[^\w@]/.test(t)) { return $.tn(t); } if (/^toggle-all/.test(t)) { a = $.el('a', { className: 'show-board-list-button', - textContent: (t.match(/-text:"(.+)"/) || [null, '+'])[1], + textContent: (match = t.match(/-text:"(.+)"/)) ? match[1] : '+', href: 'javascript:;' }); $.on(a, 'click', Header.toggleBoardList); return a; } if (/^external/.test(t)) { - a = $.el('a', { - href: (t.match(/\,"(.+)"/) || [null, '+'])[1], - textContent: (t.match(/-text:"(.+)"\,/) || [null, '+'])[1], - className: 'external' - }); - if (a.hostname === 'boards.4chan.org' && a.pathname.split('/')[1] === g.BOARD.ID) { - a.className += ' current'; + if (url = t.match(/\,"(.+)"/)) { + a = $.el('a', { + textContent: (match = t.match(/-text:"(.+)"\,/)) ? match[1] : '+', + className: 'external', + href: url[1] + }); + if (a.hostname === 'boards.4chan.org' && a.pathname.split('/')[1] === g.BOARD.ID) { + a.className += ' current'; + } + return a; } - return a; } board = /^current/.test(t) ? g.BOARD.ID : t.match(/^[^-]+/)[0]; boardID = t.split('-')[0]; @@ -15048,7 +15050,7 @@ _ref = $$("#board-list a:not(.catalog), #boardNavDesktopFoot a"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; - if (((_ref1 = a.hostname) !== 'boards.4chan.org' && _ref1 !== 'catalog.neet.tv' && _ref1 !== '4index.gropes.us') || !(board = a.pathname.split('/')[1]) || (board === 'f' || board === 'status' || board === '4chan')) { + if (((_ref1 = a.hostname) !== 'boards.4chan.org' && _ref1 !== 'catalog.neet.tv' && _ref1 !== '4index.gropes.us') || !(board = a.pathname.split('/')[1]) || (board === 'f' || board === 'status' || board === '4chan') || $.hasClass(a, 'external')) { continue; } a.href = generateURL(board); diff --git a/builds/crx/script.js b/builds/crx/script.js index d8cf79950..54af1a565 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* appchan x - Version 2.9.32 - 2014-07-30 +* appchan x - Version 2.9.32 - 2014-07-31 * * Licensed under the MIT license. * https://github.com/zixaphir/appchan-x/blob/master/LICENSE @@ -4360,29 +4360,31 @@ as = $$('#full-board-list a[title]', Header.boardList); re = /[\w@]+(-(all|title|replace|full|archive|(mode|sort|text|url):"[^"]+"(\,"[^"]+[^"]")?))*|[^\w@]+/g; nodes = text.match(re).map(function(t) { - var a, board, boardID, href, m, type, _i, _len; + var a, board, boardID, href, m, match, type, url, _i, _len; if (/^[^\w@]/.test(t)) { return $.tn(t); } if (/^toggle-all/.test(t)) { a = $.el('a', { className: 'show-board-list-button', - textContent: (t.match(/-text:"(.+)"/) || [null, '+'])[1], + textContent: (match = t.match(/-text:"(.+)"/)) ? match[1] : '+', href: 'javascript:;' }); $.on(a, 'click', Header.toggleBoardList); return a; } if (/^external/.test(t)) { - a = $.el('a', { - href: (t.match(/\,"(.+)"/) || [null, '+'])[1], - textContent: (t.match(/-text:"(.+)"\,/) || [null, '+'])[1], - className: 'external' - }); - if (a.hostname === 'boards.4chan.org' && a.pathname.split('/')[1] === g.BOARD.ID) { - a.className += ' current'; + if (url = t.match(/\,"(.+)"/)) { + a = $.el('a', { + textContent: (match = t.match(/-text:"(.+)"\,/)) ? match[1] : '+', + className: 'external', + href: url[1] + }); + if (a.hostname === 'boards.4chan.org' && a.pathname.split('/')[1] === g.BOARD.ID) { + a.className += ' current'; + } + return a; } - return a; } board = /^current/.test(t) ? g.BOARD.ID : t.match(/^[^-]+/)[0]; boardID = t.split('-')[0]; @@ -15059,7 +15061,7 @@ _ref = $$("#board-list a:not(.catalog), #boardNavDesktopFoot a"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; - if (((_ref1 = a.hostname) !== 'boards.4chan.org' && _ref1 !== 'catalog.neet.tv' && _ref1 !== '4index.gropes.us') || !(board = a.pathname.split('/')[1]) || (board === 'f' || board === 'status' || board === '4chan')) { + if (((_ref1 = a.hostname) !== 'boards.4chan.org' && _ref1 !== 'catalog.neet.tv' && _ref1 !== '4index.gropes.us') || !(board = a.pathname.split('/')[1]) || (board === 'f' || board === 'status' || board === '4chan') || $.hasClass(a, 'external')) { continue; } a.href = generateURL(board); diff --git a/src/General/Header.coffee b/src/General/Header.coffee index 31a1a796c..b7a930baa 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -151,20 +151,21 @@ Header = if /^toggle-all/.test t a = $.el 'a', - className: 'show-board-list-button' - textContent: (t.match(/-text:"(.+)"/) || [null, '+'])[1] - href: 'javascript:;' + className: 'show-board-list-button' + textContent: if match = t.match /-text:"(.+)"/ then match[1] else '+' + href: 'javascript:;' $.on a, 'click', Header.toggleBoardList return a if /^external/.test t - a = $.el 'a', - href: (t.match(/\,"(.+)"/) || [null, '+'])[1] - textContent: (t.match(/-text:"(.+)"\,/) || [null, '+'])[1] - className: 'external' - if a.hostname is 'boards.4chan.org' and a.pathname.split('/')[1] is g.BOARD.ID - a.className += ' current' - return a + if url = t.match /\,"(.+)"/ + a = $.el 'a', + textContent: if match = t.match /-text:"(.+)"\,/ then match[1] else '+' + className: 'external' + href: url[1] + if a.hostname is 'boards.4chan.org' and a.pathname.split('/')[1] is g.BOARD.ID + a.className += ' current' + return a board = if /^current/.test t g.BOARD.ID diff --git a/src/Miscellaneous/CatalogLinks.coffee b/src/Miscellaneous/CatalogLinks.coffee index e4d164ec5..3479fdc98 100755 --- a/src/Miscellaneous/CatalogLinks.coffee +++ b/src/Miscellaneous/CatalogLinks.coffee @@ -34,7 +34,8 @@ CatalogLinks = for a in $$ """#board-list a:not(.catalog), #boardNavDesktopFoot a""" continue if a.hostname not in ['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'] or !(board = a.pathname.split('/')[1]) or - board in ['f', 'status', '4chan'] + board in ['f', 'status', '4chan'] or + $.hasClass a, 'external' # Href is easier than pathname because then we don't have # conditions where External Catalog has been disabled between switches.