Make parsing of location on init available for arbitrary URLs.
This commit is contained in:
parent
ee4e72e40f
commit
57ab3cf5d1
@ -123,11 +123,30 @@ Main =
|
|||||||
<%= html(meta.name + ' has been updated to <a href="' + meta.changelog + '" target="_blank">version ${g.VERSION}</a>.') %>
|
<%= html(meta.name + ' has been updated to <a href="' + meta.changelog + '" target="_blank">version ${g.VERSION}</a>.') %>
|
||||||
new Notice 'info', el, 15
|
new Notice 'info', el, 15
|
||||||
|
|
||||||
initFeatures: ->
|
parseURL: (site=g.SITE, url=location) ->
|
||||||
{hostname, search} = location
|
r = {}
|
||||||
pathname = location.pathname.split /\/+/
|
|
||||||
g.BOARD = new Board pathname[1] unless hostname in ['www.4chan.org', 'www.4channel.org']
|
|
||||||
|
|
||||||
|
return r if !site
|
||||||
|
r.siteID = site.ID
|
||||||
|
|
||||||
|
return r if site.isBoardlessPage?(url)
|
||||||
|
pathname = url.pathname.split /\/+/
|
||||||
|
r.boardID = pathname[1]
|
||||||
|
|
||||||
|
if site.isFileURL(url)
|
||||||
|
r.VIEW = 'file'
|
||||||
|
else if site.isAuxiliaryPage?(url)
|
||||||
|
# pass
|
||||||
|
else if pathname[2] in ['thread', 'res']
|
||||||
|
r.VIEW = 'thread'
|
||||||
|
r.threadID = r.THREADID = +pathname[3].replace(/\.\w+$/, '')
|
||||||
|
else if /^(?:catalog|archive)(?:\.\w+)?$/.test(pathname[2])
|
||||||
|
r.VIEW = pathname[2].replace(/\.\w+$/, '')
|
||||||
|
else if /^(?:index|\d*)(?:\.\w+)?$/.test(pathname[2])
|
||||||
|
r.VIEW = 'index'
|
||||||
|
r
|
||||||
|
|
||||||
|
initFeatures: ->
|
||||||
$.global ->
|
$.global ->
|
||||||
document.documentElement.classList.add 'js-enabled'
|
document.documentElement.classList.add 'js-enabled'
|
||||||
window.FCX = {}
|
window.FCX = {}
|
||||||
@ -136,29 +155,17 @@ Main =
|
|||||||
# XXX https://bugs.chromium.org/p/chromium/issues/detail?id=920638
|
# XXX https://bugs.chromium.org/p/chromium/issues/detail?id=920638
|
||||||
$.ajaxPageInit?()
|
$.ajaxPageInit?()
|
||||||
|
|
||||||
switch hostname
|
$.extend g, Main.parseURL()
|
||||||
when 'www.4chan.org', 'www.4channel.org'
|
g.BOARD = new Board g.boardID if g.boardID
|
||||||
$.onExists doc, 'body', -> $.addStyle CSS.www
|
|
||||||
Captcha.replace.init()
|
|
||||||
return
|
|
||||||
when 'sys.4chan.org', 'sys.4channel.org'
|
|
||||||
if pathname[2] is 'imgboard.php'
|
|
||||||
if /\bmode=report\b/.test search
|
|
||||||
Report.init()
|
|
||||||
else if (match = search.match /\bres=(\d+)/)
|
|
||||||
$.ready ->
|
|
||||||
if Conf['404 Redirect'] and $.id('errmsg')?.textContent is 'Error: Specified thread does not exist.'
|
|
||||||
Redirect.navigate 'thread', {
|
|
||||||
boardID: g.BOARD.ID
|
|
||||||
postID: +match[1]
|
|
||||||
}
|
|
||||||
else if pathname[2] is 'post'
|
|
||||||
PostSuccessful.init()
|
|
||||||
return
|
|
||||||
|
|
||||||
if g.SITE.isFileURL()
|
if !g.VIEW
|
||||||
|
g.SITE.initAuxiliary?()
|
||||||
|
return
|
||||||
|
|
||||||
|
if g.VIEW is 'file'
|
||||||
$.asap (-> d.readyState isnt 'loading'), ->
|
$.asap (-> d.readyState isnt 'loading'), ->
|
||||||
if g.SITE.software is 'yotsuba' and Conf['404 Redirect'] and g.SITE.is404?()
|
if g.SITE.software is 'yotsuba' and Conf['404 Redirect'] and g.SITE.is404?()
|
||||||
|
pathname = location.pathname.split /\/+/
|
||||||
Redirect.navigate 'file', {
|
Redirect.navigate 'file', {
|
||||||
boardID: g.BOARD.ID
|
boardID: g.BOARD.ID
|
||||||
filename: pathname[pathname.length - 1]
|
filename: pathname[pathname.length - 1]
|
||||||
@ -173,18 +180,6 @@ Main =
|
|||||||
ImageCommon.addControls video
|
ImageCommon.addControls video
|
||||||
return
|
return
|
||||||
|
|
||||||
return if g.SITE.isAuxiliaryPage?()
|
|
||||||
|
|
||||||
if pathname[2] in ['thread', 'res']
|
|
||||||
g.VIEW = 'thread'
|
|
||||||
g.THREADID = +pathname[3].replace(/\.\w+$/, '')
|
|
||||||
else if /^(?:catalog|archive)(?:\.\w+)?$/.test(pathname[2])
|
|
||||||
g.VIEW = pathname[2].replace(/\.\w+$/, '')
|
|
||||||
else if /^(?:index|\d*)(?:\.\w+)?$/.test(pathname[2])
|
|
||||||
g.VIEW = 'index'
|
|
||||||
else
|
|
||||||
return
|
|
||||||
|
|
||||||
g.threads = new SimpleDict()
|
g.threads = new SimpleDict()
|
||||||
g.posts = new SimpleDict()
|
g.posts = new SimpleDict()
|
||||||
|
|
||||||
|
|||||||
@ -154,8 +154,8 @@ SW.tinyboard =
|
|||||||
bgColoredEl: ->
|
bgColoredEl: ->
|
||||||
$.el 'div', className: 'post reply'
|
$.el 'div', className: 'post reply'
|
||||||
|
|
||||||
isFileURL: ->
|
isFileURL: (url) ->
|
||||||
/\/src\/[^\/]+/.test(location.pathname)
|
/\/src\/[^\/]+/.test(url.pathname)
|
||||||
|
|
||||||
parseNodes: (post, nodes) ->
|
parseNodes: (post, nodes) ->
|
||||||
# Add vichan's span.poster_id around the ID if not already present.
|
# Add vichan's span.poster_id around the ID if not already present.
|
||||||
|
|||||||
@ -106,11 +106,36 @@ SW.yotsuba =
|
|||||||
isIncomplete: ->
|
isIncomplete: ->
|
||||||
return g.VIEW in ['index', 'thread'] and not $('.board + *')
|
return g.VIEW in ['index', 'thread'] and not $('.board + *')
|
||||||
|
|
||||||
isAuxiliaryPage: ->
|
isBoardlessPage: (url) ->
|
||||||
location.hostname not in ['boards.4chan.org', 'boards.4channel.org']
|
url.hostname in ['www.4chan.org', 'www.4channel.org']
|
||||||
|
|
||||||
isFileURL: ->
|
isAuxiliaryPage: (url) ->
|
||||||
ImageHost.test(location.hostname)
|
url.hostname not in ['boards.4chan.org', 'boards.4channel.org']
|
||||||
|
|
||||||
|
isFileURL: (url) ->
|
||||||
|
ImageHost.test(url.hostname)
|
||||||
|
|
||||||
|
initAuxiliary: ->
|
||||||
|
switch location.hostname
|
||||||
|
when 'www.4chan.org', 'www.4channel.org'
|
||||||
|
$.onExists doc, 'body', -> $.addStyle CSS.www
|
||||||
|
Captcha.replace.init()
|
||||||
|
return
|
||||||
|
when 'sys.4chan.org', 'sys.4channel.org'
|
||||||
|
pathname = location.pathname.split /\/+/
|
||||||
|
if pathname[2] is 'imgboard.php'
|
||||||
|
if /\bmode=report\b/.test location.search
|
||||||
|
Report.init()
|
||||||
|
else if (match = location.search.match /\bres=(\d+)/)
|
||||||
|
$.ready ->
|
||||||
|
if Conf['404 Redirect'] and $.id('errmsg')?.textContent is 'Error: Specified thread does not exist.'
|
||||||
|
Redirect.navigate 'thread', {
|
||||||
|
boardID: g.BOARD.ID
|
||||||
|
postID: +match[1]
|
||||||
|
}
|
||||||
|
else if pathname[2] is 'post'
|
||||||
|
PostSuccessful.init()
|
||||||
|
return
|
||||||
|
|
||||||
scriptData: ->
|
scriptData: ->
|
||||||
for script in $$ 'script:not([src])', d.head
|
for script in $$ 'script:not([src])', d.head
|
||||||
|
|||||||
@ -6,14 +6,10 @@ Site =
|
|||||||
|
|
||||||
init: (cb) ->
|
init: (cb) ->
|
||||||
$.extend Conf['siteProperties'], Site.defaultProperties
|
$.extend Conf['siteProperties'], Site.defaultProperties
|
||||||
{hostname} = location
|
hostname = Site.resolve()
|
||||||
while hostname and hostname not of Conf['siteProperties']
|
if hostname and Conf['siteProperties'][hostname].software of SW
|
||||||
hostname = hostname.replace(/^[^.]*\.?/, '')
|
@set hostname
|
||||||
if hostname
|
cb()
|
||||||
hostname = canonical if (canonical = Conf['siteProperties'][hostname].canonical)
|
|
||||||
if Conf['siteProperties'][hostname].software of SW
|
|
||||||
@set hostname
|
|
||||||
cb()
|
|
||||||
$.onExists doc, 'body', =>
|
$.onExists doc, 'body', =>
|
||||||
for software of SW when (changes = SW[software].detect?())
|
for software of SW when (changes = SW[software].detect?())
|
||||||
changes.software = software
|
changes.software = software
|
||||||
@ -31,6 +27,18 @@ Site =
|
|||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
|
resolve: (url=location) ->
|
||||||
|
{hostname} = url
|
||||||
|
while hostname and hostname not of Conf['siteProperties']
|
||||||
|
hostname = hostname.replace(/^[^.]*\.?/, '')
|
||||||
|
if hostname
|
||||||
|
hostname = canonical if (canonical = Conf['siteProperties'][hostname].canonical)
|
||||||
|
hostname
|
||||||
|
|
||||||
|
parseURL: (url) ->
|
||||||
|
siteID = Site.resolve url
|
||||||
|
Main.parseURL g.sites[siteID], url
|
||||||
|
|
||||||
set: (hostname) ->
|
set: (hostname) ->
|
||||||
for ID, properties of Conf['siteProperties']
|
for ID, properties of Conf['siteProperties']
|
||||||
continue if properties.canonical
|
continue if properties.canonical
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user