Read /pol/ flags from 4chan API instead of hardcoding them.

This commit is contained in:
ccd0 2017-10-27 09:18:46 -07:00
parent b00747e92e
commit 13449ae431
2 changed files with 13 additions and 36 deletions

View File

@ -3,28 +3,30 @@ BoardConfig =
init: ->
now = Date.now()
unless now - 2 * $.HOUR < (Conf['boardConfig'].lastChecked or 0) <= now
unless now - 2 * $.HOUR < (Conf['boardConfig'].lastChecked or 0) <= now and Conf['boardConfig'].troll_flags
$.ajax "#{location.protocol}//a.4cdn.org/boards.json",
onloadend: @load
else
@set Conf['boardConfig'].boards
{boards, troll_flags} = Conf['boardConfig']
@set boards, troll_flags
load: ->
if @status is 200 and @response and @response.boards
boards = {}
for board in @response.boards
boards[board.board] = board
$.set 'boardConfig', {boards, lastChecked: Date.now()}
{troll_flags} = @response
$.set 'boardConfig', {boards, troll_flags, lastChecked: Date.now()}
else
{boards} = Conf['boardConfig']
{boards, troll_flags} = Conf['boardConfig']
err = switch @status
when 0 then 'Connection Error'
when 200 then 'Invalid Data'
else "Error #{@statusText} (#{@status})"
new Notice 'warning', "Failed to load board configuration. #{err}", 20
BoardConfig.set boards
BoardConfig.set boards, troll_flags
set: (@boards) ->
set: (@boards, @troll_flags) ->
for ID, board of g.boards
board.config = @boards[ID] or {}
for cb in @cbs

View File

@ -602,37 +602,12 @@ QR =
name: 'flag'
className: 'flagSelector'
fn = (val) ->
$.add select, $.el 'option',
value: val[0]
textContent: val[1]
addFlag = (value, textContent) ->
$.add select, $.el 'option', {value, textContent}
fn flag for flag in [
['0', 'Geographic Location']
['AC', 'Anarcho-Capitalist']
['AN', 'Anarchist']
['BL', 'Black Nationalist']
['CF', 'Confederate']
['CM', 'Communist']
['CT', 'Catalonia']
['DM', 'Democrat']
['EU', 'European']
['FC', 'Fascist']
['GN', 'Gadsden']
['GY', 'Gay']
['JH', 'Jihadi']
['KN', 'Kekistani']
['MF', 'Muslim']
['NB', 'National Bolshevik']
['NZ', 'Nazi']
['PC', 'Hippie']
['PR', 'Pirate']
['RE', 'Republican']
['TM', 'Templar']
['TR', 'Tree Hugger']
['UN', 'United Nations']
['WP', 'White Supremacist']
]
addFlag '0', 'Geographic Location'
for value, textContent of BoardConfig.troll_flags
addFlag value, textContent
select