Make Catalog Links toggle work on Tinyboard/vichan. #2171
This commit is contained in:
parent
57ab3cf5d1
commit
699c1f7be5
@ -1,4 +1,6 @@
|
|||||||
Get =
|
Get =
|
||||||
|
url: (type, IDs, args...) ->
|
||||||
|
g.sites[IDs.siteID]?.urls[type] IDs, args...
|
||||||
threadExcerpt: (thread) ->
|
threadExcerpt: (thread) ->
|
||||||
{OP} = thread
|
{OP} = thread
|
||||||
excerpt = ("/#{decodeURIComponent thread.board.ID}/ - ") + (
|
excerpt = ("/#{decodeURIComponent thread.board.ID}/ - ") + (
|
||||||
|
|||||||
@ -234,7 +234,10 @@ Header =
|
|||||||
href: "/#{g.BOARD.ID}/"
|
href: "/#{g.BOARD.ID}/"
|
||||||
textContent: text or g.BOARD.ID
|
textContent: text or g.BOARD.ID
|
||||||
className: 'current'
|
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'
|
a.href += 'catalog.html'
|
||||||
else if /-(archive|expired)/.test(t)
|
else if /-(archive|expired)/.test(t)
|
||||||
a = a.firstChild # Its text node.
|
a = a.firstChild # Its text node.
|
||||||
@ -265,7 +268,7 @@ Header =
|
|||||||
if m = t.match /-(index|catalog)/
|
if m = t.match /-(index|catalog)/
|
||||||
unless boardID is 'f' and m[1] is 'catalog'
|
unless boardID is 'f' and m[1] is 'catalog'
|
||||||
a.dataset.only = m[1]
|
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'
|
$.addClass a, 'catalog' if m[1] is 'catalog'
|
||||||
else
|
else
|
||||||
return a.firstChild # Its text node.
|
return a.firstChild # Its text node.
|
||||||
|
|||||||
@ -2,6 +2,9 @@ Index =
|
|||||||
showHiddenThreads: false
|
showHiddenThreads: false
|
||||||
changed: {}
|
changed: {}
|
||||||
|
|
||||||
|
enabledOn: ({siteID, boardID}) ->
|
||||||
|
Conf['JSON Index'] and g.sites[siteID].software is 'yotsuba' and boardID isnt 'f'
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
return unless g.VIEW is 'index'
|
return unless g.VIEW is 'index'
|
||||||
|
|
||||||
@ -9,7 +12,7 @@ Index =
|
|||||||
$.one d, '4chanXInitFinished', @cb.initFinished
|
$.one d, '4chanXInitFinished', @cb.initFinished
|
||||||
$.on d, 'PostsInserted', @cb.postsInserted
|
$.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
|
@enabled = true
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
CatalogLinks =
|
CatalogLinks =
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
if g.SITE.software is 'yotsuba' and (Conf['External Catalog'] or Conf['JSON Index']) and !(Conf['JSON Index'] and g.VIEW is 'index')
|
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
|
selector = switch g.VIEW
|
||||||
@ -59,23 +58,26 @@ CatalogLinks =
|
|||||||
setLinks: (list) ->
|
setLinks: (list) ->
|
||||||
return unless (CatalogLinks.enabled ? Conf['Catalog Links']) and 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)
|
for a in $$('a:not([data-only])', list)
|
||||||
unless (board = a.dataset.board)
|
{siteID, boardID} = a.dataset
|
||||||
continue if (
|
unless siteID and boardID
|
||||||
a.hostname not in ['boards.4chan.org', 'boards.4channel.org'] or
|
{siteID, boardID, VIEW} = Site.parseURL a
|
||||||
!(board = a.pathname.split('/')[1]) or
|
continue unless (
|
||||||
board in ['f', 'status', '4chan'] or
|
siteID and boardID and
|
||||||
a.pathname.split('/')[2] is 'archive' or
|
VIEW in ['index', 'catalog'] and
|
||||||
$.hasClass a, 'external'
|
(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
|
board = {siteID, boardID}
|
||||||
# conditions where External Catalog has been disabled between switches.
|
url = if Conf['Header catalog links'] then CatalogLinks.catalog(board) else Get.url('index', board)
|
||||||
a.href = if Conf['Header catalog links'] then CatalogLinks.catalog(board) else "//#{BoardConfig.domain(board)}/#{board}/"
|
if url
|
||||||
|
a.href = url
|
||||||
if a.dataset.indexOptions and a.hostname in ['boards.4chan.org', 'boards.4channel.org'] and a.pathname.split('/')[2] is ''
|
if a.dataset.indexOptions and url.split('#')[0] is Get.url('index', board)
|
||||||
a.href += (if a.hash then '/' else '#') + a.dataset.indexOptions
|
a.href += (if a.hash then '/' else '#') + a.dataset.indexOptions
|
||||||
return
|
return
|
||||||
|
|
||||||
externalParse: ->
|
externalParse: ->
|
||||||
@ -95,17 +97,22 @@ CatalogLinks =
|
|||||||
external = (CatalogLinks.externalList["#{siteID}/#{boardID}"] or CatalogLinks.externalList["#{siteID}/*"])
|
external = (CatalogLinks.externalList["#{siteID}/#{boardID}"] or CatalogLinks.externalList["#{siteID}/*"])
|
||||||
if external then external.replace(/%board/g, boardID) else undefined
|
if external then external.replace(/%board/g, boardID) else undefined
|
||||||
|
|
||||||
catalog: (board=g.BOARD.ID) ->
|
jsonIndex: (board, hash) ->
|
||||||
siteID = '4chan.org'
|
if g.SITE.ID is board.siteID and g.BOARD.ID is board.boardID and g.VIEW is 'index'
|
||||||
if Conf['External Catalog'] and (external = CatalogLinks.external({siteID, boardID: board}))
|
hash
|
||||||
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
|
else
|
||||||
g.sites[siteID].urls.catalog?({siteID, boardID: board})
|
Get.url('index', board) + hash
|
||||||
|
|
||||||
index: (board=g.BOARD.ID) ->
|
catalog: (board=g.BOARD) ->
|
||||||
if Conf['JSON Index'] and board isnt 'f'
|
if Conf['External Catalog'] and (external = CatalogLinks.external board)
|
||||||
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"
|
external
|
||||||
|
else if Index.enabledOn(board) and Conf['Use <%= meta.name %> Catalog']
|
||||||
|
CatalogLinks.jsonIndex board, '#catalog'
|
||||||
else
|
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
|
||||||
|
|||||||
@ -46,6 +46,7 @@ SW.tinyboard =
|
|||||||
|
|
||||||
urls:
|
urls:
|
||||||
thread: ({siteID, boardID, threadID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/res/#{threadID}.html"
|
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"
|
catalog: ({siteID, boardID}) -> "#{Conf['siteProperties'][siteID]?.root or "http://#{siteID}/"}#{boardID}/catalog.html"
|
||||||
threadJSON: ({siteID, boardID, threadID}) ->
|
threadJSON: ({siteID, boardID, threadID}) ->
|
||||||
root = Conf['siteProperties'][siteID]?.root
|
root = Conf['siteProperties'][siteID]?.root
|
||||||
|
|||||||
@ -4,6 +4,7 @@ SW.yotsuba =
|
|||||||
|
|
||||||
urls:
|
urls:
|
||||||
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
|
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"
|
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"
|
threadJSON: ({boardID, threadID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/thread/#{threadID}.json"
|
||||||
threadsListJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json"
|
threadsListJSON: ({boardID}) -> "#{location.protocol}//a.4cdn.org/#{boardID}/threads.json"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user