From 13449ae43104d10c3e0befd6b9e55ea95de28e07 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 27 Oct 2017 09:18:46 -0700 Subject: [PATCH] Read /pol/ flags from 4chan API instead of hardcoding them. --- src/General/BoardConfig.coffee | 14 ++++++++------ src/Posting/QR.coffee | 35 +++++----------------------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/General/BoardConfig.coffee b/src/General/BoardConfig.coffee index bd05250a0..c1e1b1e72 100644 --- a/src/General/BoardConfig.coffee +++ b/src/General/BoardConfig.coffee @@ -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 diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index eb7b5f765..712d46f0c 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -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