Make index-related keybinds work on Tinyboard/vichan sites. #2171

This commit is contained in:
ccd0 2019-07-22 18:28:57 -07:00
parent 093bbc9905
commit df5a31a26e
3 changed files with 29 additions and 17 deletions

View File

@ -91,7 +91,7 @@ Keybinds =
return unless ThreadUpdater.enabled return unless ThreadUpdater.enabled
ThreadUpdater.update() ThreadUpdater.update()
when 'index' when 'index'
return unless Conf['JSON Index'] and g.BOARD.ID isnt 'f' return unless Index.enabled
Index.update() Index.update()
else else
return return
@ -129,47 +129,51 @@ Keybinds =
FappeTyme.toggle 'werk' FappeTyme.toggle 'werk'
# Board Navigation # Board Navigation
when Conf['Front page'] when Conf['Front page']
if Conf['JSON Index'] and g.VIEW is 'index' and g.BOARD.ID isnt 'f' if Index.enabled
Index.userPageNav 1 Index.userPageNav 1
else else
location.href = "/#{g.BOARD}/" location.href = "/#{g.BOARD}/"
when Conf['Open front page'] when Conf['Open front page']
$.open "#{location.origin}/#{g.BOARD}/" $.open "#{location.origin}/#{g.BOARD}/"
when Conf['Next page'] when Conf['Next page']
return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' return unless g.VIEW is 'index' and !g.SITE.isOnePage?(g.BOARD)
if Conf['JSON Index'] if Index.enabled
return unless Conf['Index Mode'] in ['paged', 'infinite'] return unless Conf['Index Mode'] in ['paged', 'infinite']
$('.next button', Index.pagelist).click() $('.next button', Index.pagelist).click()
else else
if form = $ '.next form' $(g.SITE.selectors.nav.next)?.click()
location.href = form.action
when Conf['Previous page'] when Conf['Previous page']
return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' return unless g.VIEW is 'index' and !g.SITE.isOnePage?(g.BOARD)
if Conf['JSON Index'] if Index.enabled
return unless Conf['Index Mode'] in ['paged', 'infinite'] return unless Conf['Index Mode'] in ['paged', 'infinite']
$('.prev button', Index.pagelist).click() $('.prev button', Index.pagelist).click()
else else
if form = $ '.prev form' $(g.SITE.selectors.nav.prev)?.click()
location.href = form.action
when Conf['Search form'] when Conf['Search form']
return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' return unless g.VIEW is 'index'
searchInput = if Conf['JSON Index'] then Index.searchInput else $.id('search-box') searchInput = if Index.enabled
Index.searchInput
else if g.SITE.selectors.searchBox
$ g.SITE.selectors.searchBox
else
undefined
return unless searchInput
Header.scrollToIfNeeded searchInput Header.scrollToIfNeeded searchInput
searchInput.focus() searchInput.focus()
when Conf['Paged mode'] when Conf['Paged mode']
return unless Conf['JSON Index'] and g.BOARD.ID isnt 'f' return unless Index.enabledOn(g.BOARD)
location.href = if g.VIEW is 'index' then '#paged' else "/#{g.BOARD}/#paged" location.href = if g.VIEW is 'index' then '#paged' else "/#{g.BOARD}/#paged"
when Conf['Infinite scrolling mode'] when Conf['Infinite scrolling mode']
return unless Conf['JSON Index'] and g.BOARD.ID isnt 'f' return unless Index.enabledOn(g.BOARD)
location.href = if g.VIEW is 'index' then '#infinite' else "/#{g.BOARD}/#infinite" location.href = if g.VIEW is 'index' then '#infinite' else "/#{g.BOARD}/#infinite"
when Conf['All pages mode'] when Conf['All pages mode']
return unless Conf['JSON Index'] and g.BOARD.ID isnt 'f' return unless Index.enabledOn(g.BOARD)
location.href = if g.VIEW is 'index' then '#all-pages' else "/#{g.BOARD}/#all-pages" location.href = if g.VIEW is 'index' then '#all-pages' else "/#{g.BOARD}/#all-pages"
when Conf['Open catalog'] when Conf['Open catalog']
return if g.BOARD.ID is 'f' return if g.BOARD.ID is 'f'
location.href = CatalogLinks.catalog() location.href = CatalogLinks.catalog()
when Conf['Cycle sort type'] when Conf['Cycle sort type']
return unless Conf['JSON Index'] and g.VIEW is 'index' and g.BOARD.ID isnt 'f' return unless Index.enabled
Index.cycleSortType() Index.cycleSortType()
# Thread Navigation # Thread Navigation
when Conf['Next thread'] when Conf['Next thread']

View File

@ -106,6 +106,9 @@ SW.tinyboard =
boardListBottom: '.boardlist.bottom' boardListBottom: '.boardlist.bottom'
styleSheet: '#stylesheet' styleSheet: '#stylesheet'
psa: '.blotter' psa: '.blotter'
nav:
prev: '.pages > form > [value=Previous]'
next: '.pages > form > [value=Next]'
xpath: xpath:
thread: 'div[starts-with(@id,"thread_")]' thread: 'div[starts-with(@id,"thread_")]'

View File

@ -16,8 +16,9 @@ SW.yotsuba =
thumb: ({boardID}, filename) -> thumb: ({boardID}, filename) ->
"#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}" "#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}"
isPrunedByAge: ({boardID}) -> boardID is 'f' isPrunedByAge: ({boardID}) -> boardID is 'f'
areMD5sDeferred: ({boardID}) -> boardID is 'f' areMD5sDeferred: ({boardID}) -> boardID is 'f'
isOnePage: ({boardID}) -> boardID is 'f'
noAudio: ({boardID}) -> BoardConfig.noAudio(boardID) noAudio: ({boardID}) -> BoardConfig.noAudio(boardID)
selectors: selectors:
@ -69,6 +70,10 @@ SW.yotsuba =
styleSheet: 'link[title=switch]' styleSheet: 'link[title=switch]'
psa: '#globalMessage' psa: '#globalMessage'
psaTop: '#globalToggle' psaTop: '#globalToggle'
searchBox: '#search-box'
nav:
prev: '.prev > form > [type=submit]'
next: '.next > form > [type=submit]'
xpath: xpath:
thread: 'div[contains(concat(" ",@class," ")," thread ")]' thread: 'div[contains(concat(" ",@class," ")," thread ")]'