Simplify usage of Redirect.navigate.

This commit is contained in:
ccd0 2015-07-18 10:45:09 -07:00
parent e2a55997ce
commit eb116cf476
2 changed files with 11 additions and 12 deletions

View File

@ -95,11 +95,13 @@ Redirect =
location.protocol is 'http:' or location.protocol is 'http:' or
Conf['Except Archives from Encryption'] Conf['Except Archives from Encryption']
navigate: (URL, alternative) -> navigate: (dest, data, alternative) ->
if URL and ( Redirect.init() unless Redirect.data
Redirect.securityCheck(URL) or url = Redirect.to dest, data
confirm "Redirect to #{URL}?\n\nYour connection will not be encrypted." if url and (
Redirect.securityCheck(url) or
confirm "Redirect to #{url}?\n\nYour connection will not be encrypted."
) )
location.replace URL location.replace url
else if alternative else if alternative
location.replace alternative location.replace alternative

View File

@ -78,20 +78,17 @@ Main =
if /\/imgboard\.php$/.test(location.pathname) and (match = location.search.match /\bres=(\d+)/) if /\/imgboard\.php$/.test(location.pathname) and (match = location.search.match /\bres=(\d+)/)
$.ready -> $.ready ->
if $.id('errmsg')?.textContent is 'Error: Specified thread does not exist.' if $.id('errmsg')?.textContent is 'Error: Specified thread does not exist.'
Redirect.init() Redirect.navigate 'thread',
Redirect.navigate Redirect.to 'thread',
boardID: g.BOARD.ID boardID: g.BOARD.ID
postID: +match[1] postID: +match[1]
return return
when 'i.4cdn.org' when 'i.4cdn.org'
$.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 d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found']
Redirect.init()
pathname = location.pathname.split '/' pathname = location.pathname.split '/'
URL = Redirect.to 'file', Redirect.navigate 'file',
boardID: g.BOARD.ID boardID: g.BOARD.ID
filename: pathname[pathname.length - 1] filename: pathname[pathname.length - 1]
Redirect.navigate URL
else if video = $ 'video' else if video = $ 'video'
if Conf['Volume in New Tab'] if Conf['Volume in New Tab']
Volume.setup video Volume.setup video
@ -169,11 +166,11 @@ Main =
if g.VIEW is 'thread' 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']
href = Redirect.to '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
Redirect.navigate href, "/#{g.BOARD}/" , "/#{g.BOARD}/"
return return
# 4chan Pass Link # 4chan Pass Link