More Tinyboard compatibility fixes in Main.coffee.

This commit is contained in:
name 2017-12-10 11:45:50 -08:00
parent ff11e462b6
commit 077d735292
2 changed files with 27 additions and 19 deletions

View File

@ -122,11 +122,10 @@ Main =
pathname = location.pathname.split /\/+/ pathname = location.pathname.split /\/+/
g.BOARD = new Board pathname[1] unless hostname is 'www.4chan.org' 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 ->
$.global -> document.documentElement.classList.add 'js-enabled'
document.documentElement.classList.add 'js-enabled' window.FCX = {}
window.FCX = {} Main.jsEnabled = $.hasClass doc, 'js-enabled'
Main.jsEnabled = $.hasClass doc, 'js-enabled'
switch hostname switch hostname
when 'www.4chan.org' when 'www.4chan.org'
@ -151,7 +150,7 @@ Main =
if ImageHost.test hostname if ImageHost.test hostname
return unless pathname[2] and not /[sm]\.jpg$/.test(pathname[2]) return unless pathname[2] and not /[sm]\.jpg$/.test(pathname[2])
$.asap (-> d.readyState isnt 'loading'), -> $.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', { Redirect.navigate 'file', {
boardID: g.BOARD.ID boardID: g.BOARD.ID
filename: pathname[pathname.length - 1] filename: pathname[pathname.length - 1]
@ -166,7 +165,7 @@ Main =
ImageCommon.addControls video ImageCommon.addControls video
return return
return unless hostname is 'boards.4chan.org' return if Site.isAuxiliaryPage?()
if pathname[2] in ['thread', 'res'] if pathname[2] in ['thread', 'res']
g.VIEW = 'thread' g.VIEW = 'thread'
@ -265,20 +264,19 @@ Main =
} }
initReady: -> initReady: ->
# XXX Sometimes threads don't 404 but are left over as stubs containing one garbage reply post. if Site.is404?()
if g.VIEW is 'thread' and (d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] or ($('.board') and not $('.opContainer'))) if g.VIEW is 'thread'
ThreadWatcher.set404 g.BOARD.ID, g.THREADID, -> ThreadWatcher.set404 g.BOARD.ID, g.THREADID, ->
if Conf['404 Redirect'] if Conf['404 Redirect']
Redirect.navigate 'thread', Redirect.navigate 'thread',
boardID: g.BOARD.ID boardID: g.BOARD.ID
threadID: g.THREADID threadID: g.THREADID
postID: +location.hash.match /\d+/ # post number or 0 postID: +location.hash.match /\d+/ # post number or 0
, "/#{g.BOARD}/" , "/#{g.BOARD}/"
return return
return if d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] if Site.isIncomplete?()
if g.VIEW in ['index', 'thread'] and not $('.board + *')
msg = $.el 'div', msg = $.el 'div',
<%= html('The page didn&#039;t load completely.<br>Some features may not work unless you <a href="javascript:;">reload</a>.') %> <%= html('The page didn&#039;t load completely.<br>Some features may not work unless you <a href="javascript:;">reload</a>.') %>
$.on $('a', msg), 'click', -> location.reload() $.on $('a', msg), 'click', -> location.reload()

View File

@ -58,6 +58,16 @@ SW.yotsuba =
!$('link[href*="favicon-status.ico"]', d.head) and !$('link[href*="favicon-status.ico"]', d.head) and
d.title not in ['4chan - Temporarily Offline', '4chan - Error', '504 Gateway Time-out'] 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: -> scriptData: ->
for script in $$ 'script:not([src])', d.head for script in $$ 'script:not([src])', d.head
return script.textContent if /\bcooldowns *=/.test script.textContent return script.textContent if /\bcooldowns *=/.test script.textContent