GM_getValue may not have been updated when storage event is handled.
This commit is contained in:
parent
06d7b75558
commit
3fdfc7436d
@ -522,23 +522,24 @@ else if GM_deleteValue? or $.hasStorage
|
|||||||
$.oldValue[key] = $.getValue key
|
$.oldValue[key] = $.getValue key
|
||||||
|
|
||||||
do ->
|
do ->
|
||||||
onChange = (key) ->
|
onChange = ({key, newValue}) ->
|
||||||
return unless cb = $.syncing[key]
|
return unless cb = $.syncing[key]
|
||||||
newValue = $.getValue key
|
|
||||||
return if newValue is $.oldValue[key]
|
|
||||||
if newValue?
|
if newValue?
|
||||||
|
return if newValue is $.oldValue[key]
|
||||||
$.oldValue[key] = newValue
|
$.oldValue[key] = newValue
|
||||||
cb JSON.parse(newValue), key[g.NAMESPACE.length..]
|
cb JSON.parse(newValue), key[g.NAMESPACE.length..]
|
||||||
else
|
else
|
||||||
|
return unless $.oldValue[key]?
|
||||||
delete $.oldValue[key]
|
delete $.oldValue[key]
|
||||||
cb undefined, key[g.NAMESPACE.length..]
|
cb undefined, key[g.NAMESPACE.length..]
|
||||||
$.on window, 'storage', ({key}) -> onChange key
|
$.on window, 'storage', onChange
|
||||||
|
|
||||||
$.forceSync = (key) ->
|
$.forceSync = (key) ->
|
||||||
# Storage events don't work across origins
|
# Storage events don't work across origins
|
||||||
# e.g. http://boards.4chan.org and https://boards.4chan.org
|
# e.g. http://boards.4chan.org and https://boards.4chan.org
|
||||||
# so force a check for changes to avoid lost data.
|
# so force a check for changes to avoid lost data.
|
||||||
onChange g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
|
onChange {key, newValue: $.getValue key}
|
||||||
else
|
else
|
||||||
$.sync = ->
|
$.sync = ->
|
||||||
$.forceSync = ->
|
$.forceSync = ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user