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

View File

@ -602,37 +602,12 @@ QR =
name: 'flag' name: 'flag'
className: 'flagSelector' className: 'flagSelector'
fn = (val) -> addFlag = (value, textContent) ->
$.add select, $.el 'option', $.add select, $.el 'option', {value, textContent}
value: val[0]
textContent: val[1]
fn flag for flag in [ addFlag '0', 'Geographic Location'
['0', 'Geographic Location'] for value, textContent of BoardConfig.troll_flags
['AC', 'Anarcho-Capitalist'] addFlag value, textContent
['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']
]
select select