From df5a31a26e2f514c6d4446ab435cd92210a62ce8 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 22 Jul 2019 18:28:57 -0700 Subject: [PATCH] Make index-related keybinds work on Tinyboard/vichan sites. #2171 --- src/Miscellaneous/Keybinds.coffee | 36 +++++++++++++++++-------------- src/site/SW.tinyboard.coffee | 3 +++ src/site/SW.yotsuba.coffee | 7 +++++- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index 00a702ea4..2db3006ea 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -91,7 +91,7 @@ Keybinds = return unless ThreadUpdater.enabled ThreadUpdater.update() when 'index' - return unless Conf['JSON Index'] and g.BOARD.ID isnt 'f' + return unless Index.enabled Index.update() else return @@ -129,47 +129,51 @@ Keybinds = FappeTyme.toggle 'werk' # Board Navigation 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 else location.href = "/#{g.BOARD}/" when Conf['Open front page'] $.open "#{location.origin}/#{g.BOARD}/" when Conf['Next page'] - return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' - if Conf['JSON Index'] + return unless g.VIEW is 'index' and !g.SITE.isOnePage?(g.BOARD) + if Index.enabled return unless Conf['Index Mode'] in ['paged', 'infinite'] $('.next button', Index.pagelist).click() else - if form = $ '.next form' - location.href = form.action + $(g.SITE.selectors.nav.next)?.click() when Conf['Previous page'] - return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' - if Conf['JSON Index'] + return unless g.VIEW is 'index' and !g.SITE.isOnePage?(g.BOARD) + if Index.enabled return unless Conf['Index Mode'] in ['paged', 'infinite'] $('.prev button', Index.pagelist).click() else - if form = $ '.prev form' - location.href = form.action + $(g.SITE.selectors.nav.prev)?.click() when Conf['Search form'] - return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f' - searchInput = if Conf['JSON Index'] then Index.searchInput else $.id('search-box') + return unless g.VIEW is 'index' + searchInput = if Index.enabled + Index.searchInput + else if g.SITE.selectors.searchBox + $ g.SITE.selectors.searchBox + else + undefined + return unless searchInput Header.scrollToIfNeeded searchInput searchInput.focus() 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" 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" 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" when Conf['Open catalog'] return if g.BOARD.ID is 'f' location.href = CatalogLinks.catalog() 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() # Thread Navigation when Conf['Next thread'] diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 3fa22b003..f1f78319f 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -106,6 +106,9 @@ SW.tinyboard = boardListBottom: '.boardlist.bottom' styleSheet: '#stylesheet' psa: '.blotter' + nav: + prev: '.pages > form > [value=Previous]' + next: '.pages > form > [value=Next]' xpath: thread: 'div[starts-with(@id,"thread_")]' diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee index e6779212c..87438498b 100644 --- a/src/site/SW.yotsuba.coffee +++ b/src/site/SW.yotsuba.coffee @@ -16,8 +16,9 @@ SW.yotsuba = thumb: ({boardID}, filename) -> "#{location.protocol}//#{ImageHost.thumbHost()}/#{boardID}/#{filename}" - isPrunedByAge: ({boardID}) -> boardID is 'f' + isPrunedByAge: ({boardID}) -> boardID is 'f' areMD5sDeferred: ({boardID}) -> boardID is 'f' + isOnePage: ({boardID}) -> boardID is 'f' noAudio: ({boardID}) -> BoardConfig.noAudio(boardID) selectors: @@ -69,6 +70,10 @@ SW.yotsuba = styleSheet: 'link[title=switch]' psa: '#globalMessage' psaTop: '#globalToggle' + searchBox: '#search-box' + nav: + prev: '.prev > form > [type=submit]' + next: '.next > form > [type=submit]' xpath: thread: 'div[contains(concat(" ",@class," ")," thread ")]'