Site software autodetection.

This commit is contained in:
name 2017-12-11 03:29:58 -08:00
parent 243c807d5f
commit 2d14dd5a61
3 changed files with 21 additions and 8 deletions

View File

@ -103,7 +103,7 @@ Main =
for key, val of Conf
Conf[key] = items[key] ? val
Main.initFeatures()
Site.init Main.initFeatures
upgrade: (items) ->
{previousversion} = items
@ -116,9 +116,6 @@ Main =
new Notice 'info', el, 15
initFeatures: ->
Site.init()
return unless Site.software
{hostname, search} = location
pathname = location.pathname.split /\/+/
g.BOARD = new Board pathname[1] unless hostname is 'www.4chan.org'

View File

@ -1,6 +1,11 @@
SW.tinyboard =
isOPContainerThread: true
detect: ->
for script in $$ 'script:not([src])', d.head
return true if /\bvar configRoot=".*?"/.test(script.textContent)
false
selectors:
board: 'form[name="postcontrols"]'
thread: 'div[id^="thread_"]'

View File

@ -1,5 +1,5 @@
Site =
init: ->
init: (cb) ->
swDict = {}
for line in Conf['siteSoftware'].split('\n') when line[0] isnt '#'
[hostname, software] = line.split(' ')
@ -7,7 +7,18 @@ Site =
{hostname} = location
while hostname and hostname not of swDict
hostname = hostname.replace(/^[^.]*\.?/, '')
return unless hostname
@hostname = hostname
@software = swDict[hostname]
if hostname
@set hostname, swDict[hostname]
cb()
else
$.onExists doc, 'body', =>
for software of SW
if SW[software].detect?()
@set location.hostname.replace(/^www\./, ''), software
Conf['siteSoftware'] += "\n#{@hostname} #{@software}"
$.set 'siteSoftware', Conf['siteSoftware']
cb()
return
set: (@hostname, @software) ->
$.extend @, SW[@software]