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 for key, val of Conf
Conf[key] = items[key] ? val Conf[key] = items[key] ? val
Main.initFeatures() Site.init Main.initFeatures
upgrade: (items) -> upgrade: (items) ->
{previousversion} = items {previousversion} = items
@ -116,9 +116,6 @@ Main =
new Notice 'info', el, 15 new Notice 'info', el, 15
initFeatures: -> initFeatures: ->
Site.init()
return unless Site.software
{hostname, search} = location {hostname, search} = location
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'

View File

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

View File

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