Revert "Revert "Fetch boards.json data.""
This reverts commit cc03357e071dc33bc54d4e25870998bde2d34139.
This commit is contained in:
parent
21849f79c8
commit
a193d0a3ac
32
src/General/BoardsJSON.coffee
Normal file
32
src/General/BoardsJSON.coffee
Normal file
@ -0,0 +1,32 @@
|
||||
BoardsJSON =
|
||||
cbs: []
|
||||
|
||||
init: ->
|
||||
if (Conf['boardsJSON'].lastChecked or 0) < Date.now() - 2 * $.HOUR
|
||||
$.ajax '//a.4cdn.org/boards.json', onloadend: @load
|
||||
else
|
||||
@set Conf['boardsJSON'].boards
|
||||
|
||||
load: ->
|
||||
if @status is 200
|
||||
boards = {}
|
||||
for board in @response.boards
|
||||
boards[board.board] = board
|
||||
$.set 'boardsJSON', {boards, lastChecked: Date.now()}
|
||||
else
|
||||
{boards} = Conf['boardsJSON']
|
||||
new Notice 'warning', "Failed to load boards JSON. Error #{@statusText} (#{@status})", 20
|
||||
BoardsJSON.set boards
|
||||
|
||||
set: (@boards) ->
|
||||
for ID, board of @boards
|
||||
g.boards[ID]?.json = board
|
||||
for cb in @cbs
|
||||
$.queueTask cb
|
||||
return
|
||||
|
||||
ready: (cb) ->
|
||||
if @boards
|
||||
cb()
|
||||
else
|
||||
@cbs.push cb
|
||||
@ -4,5 +4,6 @@ class Board
|
||||
constructor: (@ID) ->
|
||||
@threads = new SimpleDict()
|
||||
@posts = new SimpleDict()
|
||||
@json = BoardsJSON.boards?[@ID]
|
||||
|
||||
g.boards[@] = @
|
||||
|
||||
@ -43,6 +43,7 @@ Main =
|
||||
|
||||
for db in DataBoard.keys
|
||||
Conf[db] = boards: {}
|
||||
Conf['boardsJSON'] = boards: {}
|
||||
Conf['archives'] = Redirect.archives
|
||||
Conf['selectedArchives'] = {}
|
||||
Conf['cooldowns'] = {}
|
||||
@ -430,6 +431,7 @@ Main =
|
||||
|
||||
features: [
|
||||
['Polyfill', Polyfill]
|
||||
['Boards JSON', BoardsJSON]
|
||||
['Normalize URL', NormalizeURL]
|
||||
['Captcha Configuration', Captcha.replace]
|
||||
['Redirect', Redirect]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user