Make Catalog Links toggle work on Tinyboard/vichan. #2171

This commit is contained in:
ccd0 2019-07-21 17:14:18 -07:00
parent 57ab3cf5d1
commit 699c1f7be5
6 changed files with 46 additions and 29 deletions

View File

@ -1,4 +1,6 @@
Get =
url: (type, IDs, args...) ->
g.sites[IDs.siteID]?.urls[type] IDs, args...
threadExcerpt: (thread) ->
{OP} = thread
excerpt = ("/#{decodeURIComponent thread.board.ID}/ - ") + (

View File

@ -234,7 +234,10 @@ Header =
href: "/#{g.BOARD.ID}/"
textContent: text or g.BOARD.ID
className: 'current'
if /-catalog/.test(t)
if /-index/.test(t)
a.dataset.only = 'index'
else if /-catalog/.test(t)
a.dataset.only = 'catalog'
a.href += 'catalog.html'
else if /-(archive|expired)/.test(t)
a = a.firstChild # Its text node.
@ -265,7 +268,7 @@ Header =
if m = t.match /-(index|catalog)/
unless boardID is 'f' and m[1] is 'catalog'
a.dataset.only = m[1]
a.href = CatalogLinks[m[1]] boardID
a.href = CatalogLinks[m[1]] {siteID: '4chan.org', boardID}
$.addClass a, 'catalog' if m[1] is 'catalog'
else
return a.firstChild # Its text node.

View File

@ -2,6 +2,9 @@ Index =
showHiddenThreads: false
changed: {}
enabledOn: ({siteID, boardID}) ->
Conf['JSON Index'] and g.sites[siteID].software is 'yotsuba' and boardID isnt 'f'
init: ->
return unless g.VIEW is 'index'
@ -9,7 +12,7 @@ Index =
$.one d, '4chanXInitFinished', @cb.initFinished
$.on d, 'PostsInserted', @cb.postsInserted
return unless Conf['JSON Index'] and g.SITE.software is 'yotsuba' and g.BOARD.ID isnt 'f'
return unless @enabledOn g.BOARD
@enabled = true

View File

@ -1,5 +1,4 @@
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
@ -59,23 +58,26 @@ CatalogLinks =
setLinks: (list) ->
return unless (CatalogLinks.enabled ? Conf['Catalog Links']) and list
# do not transform links unless they differ from the expected value at most by this tail
tail = /(?:index)?(?:\.\w+)?$/
for a in $$('a:not([data-only])', list)
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'
{siteID, boardID} = a.dataset
unless siteID and boardID
{siteID, boardID, VIEW} = Site.parseURL a
continue unless (
siteID and boardID and
VIEW in ['index', 'catalog'] and
(a.dataset.indexOptions or a.href.replace(tail, '') is Get.url(VIEW, {siteID, boardID}).replace(tail, ''))
)
a.dataset.board = board
$.extend a.dataset, {siteID, boardID}
# Href is easier than pathname because then we don't have
# conditions where External Catalog has been disabled between switches.
a.href = if Conf['Header catalog links'] then CatalogLinks.catalog(board) else "//#{BoardConfig.domain(board)}/#{board}/"
if a.dataset.indexOptions and a.hostname in ['boards.4chan.org', 'boards.4channel.org'] and a.pathname.split('/')[2] is ''
a.href += (if a.hash then '/' else '#') + a.dataset.indexOptions
board = {siteID, boardID}
url = if Conf['Header catalog links'] then CatalogLinks.catalog(board) else Get.url('index', board)
if url
a.href = url
if a.dataset.indexOptions and url.split('#')[0] is Get.url('index', board)
a.href += (if a.hash then '/' else '#') + a.dataset.indexOptions
return
externalParse: ->
@ -95,17 +97,22 @@ CatalogLinks =
external = (CatalogLinks.externalList["#{siteID}/#{boardID}"] or CatalogLinks.externalList["#{siteID}/*"])
if external then external.replace(/%board/g, boardID) else undefined
catalog: (board=g.BOARD.ID) ->
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"
jsonIndex: (board, hash) ->
if g.SITE.ID is board.siteID and g.BOARD.ID is board.boardID and g.VIEW is 'index'
hash
else
g.sites[siteID].urls.catalog?({siteID, boardID: board})
Get.url('index', board) + hash
index: (board=g.BOARD.ID) ->
if Conf['JSON Index'] and board isnt 'f'
if location.hostname in ['boards.4chan.org', 'boards.4channel.org'] and g.BOARD.ID is board and g.VIEW is 'index' then '#index' else "//#{BoardConfig.domain(board)}/#{board}/#index"
catalog: (board=g.BOARD) ->
if Conf['External Catalog'] and (external = CatalogLinks.external board)
external
else if Index.enabledOn(board) and Conf['Use <%= meta.name %> Catalog']
CatalogLinks.jsonIndex board, '#catalog'
else
"//#{BoardConfig.domain(board)}/#{board}/"
Get.url 'catalog', board
index: (board=g.BOARD) ->
if Index.enabledOn(board)
CatalogLinks.jsonIndex board, '#index'
else
Get.url 'index', board

View File

@ -46,6 +46,7 @@ SW.tinyboard =
urls:
thread: ({siteID, boardID, threadID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/res/#{threadID}.html"
index: ({siteID, boardID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/"
catalog: ({siteID, boardID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/catalog.html"
threadJSON: ({siteID, boardID, threadID}) ->
root = Conf['siteProperties'][siteID]?.root

View File

@ -4,6 +4,7 @@ SW.yotsuba =
urls:
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
index: ({boardID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/"
catalog: ({boardID}) -> if boardID is 'f' then undefined else "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/catalog"
threadJSON: ({boardID, threadID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.json"
threadsListJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json"