From 0aeed5edaa63e88cea7db8f19efcdd97cbaf5f9c Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 21 Jul 2019 07:51:02 -0700 Subject: [PATCH] Make list of boards with external catalog user-editable. #570, #525 --- src/General/Settings/Advanced.html | 10 +++++++ src/Miscellaneous/CatalogLinks.coffee | 39 ++++++++++++++++++++------- src/config/Config.coffee | 4 +++ src/css/style.css | 3 ++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/General/Settings/Advanced.html b/src/General/Settings/Advanced.html index 36333e97e..03d81f883 100644 --- a/src/General/Settings/Advanced.html +++ b/src/General/Settings/Advanced.html @@ -19,6 +19,16 @@ Last updated: +
+ External Catalog +
External Catalog is disabled.
+
+ URLs of external catalog sites, where %board is to be replaced by the board name.
+ Each URL should be followed by ;boards: and optionally ;exclude: and a list of supported/excluded boards in the format explained in the Filter guide. +
+ +
+
Override 4chan Image Host
Change 4chan image links to this domain. Leave blank for no change.
diff --git a/src/Miscellaneous/CatalogLinks.coffee b/src/Miscellaneous/CatalogLinks.coffee index 91c91a8c3..e0ae26d5e 100644 --- a/src/Miscellaneous/CatalogLinks.coffee +++ b/src/Miscellaneous/CatalogLinks.coffee @@ -1,4 +1,5 @@ CatalogLinks = + init: -> if g.SITE.software is 'yotsuba' and (Conf['External Catalog'] or Conf['JSON Index']) and !(Conf['JSON Index'] and g.VIEW is 'index') selector = switch g.VIEW @@ -58,13 +59,15 @@ CatalogLinks = return unless (CatalogLinks.enabled ? Conf['Catalog Links']) and list for a in $$('a:not([data-only])', list) - continue if ( - a.hostname not in ['boards.4chan.org', 'boards.4channel.org', 'catalog.neet.tv'] or - !(board = a.pathname.split('/')[1]) or - board in ['f', 'status', '4chan'] or - a.pathname.split('/')[2] is 'archive' or - $.hasClass a, 'external' - ) + unless (board = a.dataset.board) + continue if ( + a.hostname not in ['boards.4chan.org', 'boards.4channel.org'] or + !(board = a.pathname.split('/')[1]) or + board in ['f', 'status', '4chan'] or + a.pathname.split('/')[2] is 'archive' or + $.hasClass a, 'external' + ) + a.dataset.board = board # Href is easier than pathname because then we don't have # conditions where External Catalog has been disabled between switches. @@ -74,9 +77,27 @@ CatalogLinks = a.href += (if a.hash then '/' else '#') + a.dataset.indexOptions return + externalParse: -> + CatalogLinks.externalList = {} + for line in Conf['externalCatalogURLs'].split '\n' + continue if line[0] is '#' + url = line.split(';')[0] + boards = Filter.parseBoards(line.match(/;boards:([^;]+)/)?[1] or '*') + excludes = Filter.parseBoards(line.match(/;exclude:([^;]+)/)?[1]) or {} + for board of boards + unless excludes[board] or excludes[board.split('/')[0] + '/*'] + CatalogLinks.externalList[board] = url + return + + external: ({siteID, boardID}) -> + CatalogLinks.externalParse() unless CatalogLinks.externalList + external = (CatalogLinks.externalList["#{siteID}/#{boardID}"] or CatalogLinks.externalList["#{siteID}/*"]) + if external then external.replace(/%board/g, boardID) else undefined + catalog: (board=g.BOARD.ID) -> - if Conf['External Catalog'] and board in ['3', 'a', 'adv', 'an', 'asp', 'biz', 'c', 'cgl', 'ck', 'cm', 'co', 'diy', 'f', 'fa', 'fit', 'g', 'gd', 'his', 'i', 'int', 'jp', 'k', 'lgbt', 'lit', 'm', 'mlp', 'mu', 'n', 'news', 'o', 'out', 'p', 'po', 'pol', 's4s', 'sci', 'sp', 'tg', 'toy', 'trv', 'tv', 'v', 'vg', 'vip', 'vp', 'vr', 'w', 'wg', 'wsg', 'wsr', 'x'] - "//catalog.neet.tv/#{board}/" + siteID = '4chan.org' + if Conf['External Catalog'] and (external = CatalogLinks.external({siteID, boardID: board})) + external else if Conf['JSON Index'] and Conf['Use <%= meta.name %> Catalog'] if location.hostname in ['boards.4chan.org', 'boards.4channel.org'] and g.BOARD.ID is board and g.VIEW is 'index' then '#catalog' else "//#{BoardConfig.domain(board)}/#{board}/#catalog" else diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 57be795fe..6c13b63dc 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -825,6 +825,10 @@ Config = lastarchivecheck: 0 archiveAutoUpdate: true + externalCatalogURLs: """ + //catalog.neet.tv/%board/;boards:4chan.org:3,a,adv,an,asp,biz,c,cgl,ck,cm,co,diy,f,fa,fit,g,gd,his,i,int,jp,k,lgbt,lit,m,mlp,mu,n,news,o,out,p,po,pol,s4s,sci,sp,tg,toy,trv,tv,v,vg,vip,vp,vr,w,wg,wsg,wsr,x + """ + boardnav: """ [ toggle-all ] a-replace diff --git a/src/css/style.css b/src/css/style.css index 7fd7f1c70..0ba73a513 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -658,7 +658,8 @@ div[data-checked="false"] > .suboption-list { .section-advanced textarea { height: 150px; } -.section-advanced textarea[name="archiveLists"] { +.section-advanced textarea[name="archiveLists"], +.section-advanced textarea[name="externalCatalogURLs"] { height: 75px; } .section-advanced .archive-cell {