Fix race condition in QR personas.

This commit is contained in:
ccd0 2016-04-20 01:17:45 -07:00
parent 01e966e11a
commit 0a05cac9fb
3 changed files with 28 additions and 34 deletions

View File

@ -558,7 +558,7 @@ QR =
$.set 'QR Size', @style.cssText $.set 'QR Size', @style.cssText
QR.generatePostableThreadsList() QR.generatePostableThreadsList()
QR.persona.init() QR.persona.load()
new QR.post true new QR.post true
QR.status() QR.status()
QR.cooldown.setup() QR.cooldown.setup()
@ -643,7 +643,7 @@ QR =
spoiler: post.spoiler spoiler: post.spoiler
textonly: textOnly textonly: textOnly
mode: 'regist' mode: 'regist'
pwd: QR.persona.pwd pwd: QR.persona.getPassword()
options = options =
responseType: 'document' responseType: 'document'

View File

@ -1,20 +1,17 @@
QR.persona = QR.persona =
pwd: ''
always: {} always: {}
init: -> types:
QR.persona.getPassword() name: []
$.get 'QR.personas', Conf['QR.personas'], ({'QR.personas': personas}) -> email: []
types = sub: []
name: []
email: []
sub: []
for item in personas.split '\n'
QR.persona.parseItem item.trim(), types
for type, arr of types
QR.persona.loadPersonas type, arr
return
parseItem: (item, types) -> init: ->
return unless Conf['Quick Reply'] or (Conf['Menu'] and Conf['Delete Link'])
for item in Conf['QR.personas'].split '\n'
QR.persona.parseItem item.trim()
return
parseItem: (item) ->
return if item[0] is '#' return if item[0] is '#'
return unless match = item.match /(name|options|email|subject|password):"(.*)"/i return unless match = item.match /(name|options|email|subject|password):"(.*)"/i
[match, type, val] = match [match, type, val] = match
@ -36,28 +33,24 @@ QR.persona =
if /always/i.test item if /always/i.test item
QR.persona.always[type] = val QR.persona.always[type] = val
unless val in types[type] unless val in QR.persona.types[type]
types[type].push val QR.persona.types[type].push val
loadPersonas: (type, arr) -> load: ->
list = $ "#list-#{type}", QR.nodes.el for type, arr of QR.persona.types
for val in arr when val list = $ "#list-#{type}", QR.nodes.el
$.add list, $.el 'option', for val in arr when val
textContent: val $.add list, $.el 'option',
textContent: val
return return
getPassword: -> getPassword: ->
unless QR.persona.pwd if QR.persona.pwd?
QR.persona.pwd = if m = d.cookie.match /4chan_pass=([^;]+)/ QR.persona.pwd
decodeURIComponent m[1] else if (m = d.cookie.match /4chan_pass=([^;]+)/)
else if input = $.id 'postPassword' decodeURIComponent m[1]
input.value else
else ''
# If we're in a closed thread, #postPassword isn't available.
# And since #delPassword.value is only filled on window.onload
# we'd rather use #postPassword when we can.
$.id('delPassword')?.value or ''
return QR.persona.pwd
get: (cb) -> get: (cb) ->
$.get 'QR.persona', {}, ({'QR.persona': persona}) -> $.get 'QR.persona', {}, ({'QR.persona': persona}) ->

View File

@ -415,6 +415,7 @@ Main =
['Reply Hiding Buttons', PostHiding] ['Reply Hiding Buttons', PostHiding]
['Recursive', Recursive] ['Recursive', Recursive]
['Strike-through Quotes', QuoteStrikeThrough] ['Strike-through Quotes', QuoteStrikeThrough]
['Quick Reply Personas', QR.persona]
['Quick Reply', QR] ['Quick Reply', QR]
['Cooldown', QR.cooldown] ['Cooldown', QR.cooldown]
['Pass Link', PassLink] ['Pass Link', PassLink]