From 077d735292c41a31c287742958e2cc57f376bf80 Mon Sep 17 00:00:00 2001 From: name Date: Sun, 10 Dec 2017 11:45:50 -0800 Subject: [PATCH] More Tinyboard compatibility fixes in Main.coffee. --- src/main/Main.coffee | 36 +++++++++++++++++------------------- src/site/SW.yotsuba.coffee | 10 ++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/Main.coffee b/src/main/Main.coffee index 69d0b7b62..b4791171a 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -122,11 +122,10 @@ Main = pathname = location.pathname.split /\/+/ g.BOARD = new Board pathname[1] unless hostname is 'www.4chan.org' - if hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org'] - $.global -> - document.documentElement.classList.add 'js-enabled' - window.FCX = {} - Main.jsEnabled = $.hasClass doc, 'js-enabled' + $.global -> + document.documentElement.classList.add 'js-enabled' + window.FCX = {} + Main.jsEnabled = $.hasClass doc, 'js-enabled' switch hostname when 'www.4chan.org' @@ -151,7 +150,7 @@ Main = if ImageHost.test hostname return unless pathname[2] and not /[sm]\.jpg$/.test(pathname[2]) $.asap (-> d.readyState isnt 'loading'), -> - if Conf['404 Redirect'] and d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] + if Conf['404 Redirect'] and Site.is404?() Redirect.navigate 'file', { boardID: g.BOARD.ID filename: pathname[pathname.length - 1] @@ -166,7 +165,7 @@ Main = ImageCommon.addControls video return - return unless hostname is 'boards.4chan.org' + return if Site.isAuxiliaryPage?() if pathname[2] in ['thread', 'res'] g.VIEW = 'thread' @@ -265,20 +264,19 @@ Main = } initReady: -> - # XXX Sometimes threads don't 404 but are left over as stubs containing one garbage reply post. - if g.VIEW is 'thread' and (d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] or ($('.board') and not $('.opContainer'))) - ThreadWatcher.set404 g.BOARD.ID, g.THREADID, -> - if Conf['404 Redirect'] - Redirect.navigate 'thread', - boardID: g.BOARD.ID - threadID: g.THREADID - postID: +location.hash.match /\d+/ # post number or 0 - , "/#{g.BOARD}/" + if Site.is404?() + if g.VIEW is 'thread' + ThreadWatcher.set404 g.BOARD.ID, g.THREADID, -> + if Conf['404 Redirect'] + Redirect.navigate 'thread', + boardID: g.BOARD.ID + threadID: g.THREADID + postID: +location.hash.match /\d+/ # post number or 0 + , "/#{g.BOARD}/" + return - return if d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] - - if g.VIEW in ['index', 'thread'] and not $('.board + *') + if Site.isIncomplete?() msg = $.el 'div', <%= html('The page didn't load completely.
Some features may not work unless you reload.') %> $.on $('a', msg), 'click', -> location.reload() diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee index 41fdd3742..ca029b6ab 100644 --- a/src/site/SW.yotsuba.coffee +++ b/src/site/SW.yotsuba.coffee @@ -58,6 +58,16 @@ SW.yotsuba = !$('link[href*="favicon-status.ico"]', d.head) and d.title not in ['4chan - Temporarily Offline', '4chan - Error', '504 Gateway Time-out'] + is404: -> + # XXX Sometimes threads don't 404 but are left over as stubs containing one garbage reply post. + d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] or (g.VIEW is 'thread' and $('.board') and not $('.opContainer')) + + isIncomplete: -> + return g.VIEW in ['index', 'thread'] and not $('.board + *') + + isAuxiliaryPage: -> + location.hostname isnt 'boards.4chan.org' + scriptData: -> for script in $$ 'script:not([src])', d.head return script.textContent if /\bcooldowns *=/.test script.textContent