Only save to localStorage if it's a key we sync between tabs.
Stay eco-friendly!
This commit is contained in:
parent
4d886fe85c
commit
be267adc57
20
lib/$.coffee
20
lib/$.coffee
@ -195,20 +195,20 @@ $.extend $,
|
|||||||
# Round to an integer otherwise.
|
# Round to an integer otherwise.
|
||||||
Math.round size
|
Math.round size
|
||||||
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
||||||
|
syncing: {}
|
||||||
sync: do ->
|
sync: do ->
|
||||||
cbs = {}
|
|
||||||
<% if (type === 'crx') { %>
|
<% if (type === 'crx') { %>
|
||||||
chrome.storage.onChanged.addListener (changes) ->
|
chrome.storage.onChanged.addListener (changes) ->
|
||||||
for key of changes
|
for key of changes
|
||||||
if cb = cbs[key]
|
if cb = $.syncing[key]
|
||||||
cb changes[key].newValue
|
cb changes[key].newValue
|
||||||
return
|
return
|
||||||
(key, cb) -> cbs[key] = cb
|
(key, cb) -> $.syncing[key] = cb
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
$.on window, 'storage', (e) ->
|
$.on window, 'storage', (e) ->
|
||||||
if cb = cbs[e.key]
|
if cb = $.syncing[e.key]
|
||||||
cb JSON.parse e.newValue
|
cb JSON.parse e.newValue
|
||||||
(key, cb) -> cbs[g.NAMESPACE + key] = cb
|
(key, cb) -> $.syncing[g.NAMESPACE + key] = cb
|
||||||
<% } %>
|
<% } %>
|
||||||
item: (key, val) ->
|
item: (key, val) ->
|
||||||
item = {}
|
item = {}
|
||||||
@ -259,8 +259,9 @@ do ->
|
|||||||
$.set = (key, val) ->
|
$.set = (key, val) ->
|
||||||
key = g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
val = JSON.stringify val
|
val = JSON.stringify val
|
||||||
# for `storage` events
|
if key of $.syncing
|
||||||
localStorage.setItem key, val
|
# for `storage` events
|
||||||
|
localStorage.setItem key, val
|
||||||
scriptStorage[key] = val
|
scriptStorage[key] = val
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
# http://wiki.greasespot.net/Main_Page
|
# http://wiki.greasespot.net/Main_Page
|
||||||
@ -286,7 +287,8 @@ do ->
|
|||||||
set: (key, val) ->
|
set: (key, val) ->
|
||||||
key = g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
val = JSON.stringify val
|
val = JSON.stringify val
|
||||||
# for `storage` events
|
if key of $.syncing
|
||||||
localStorage.setItem key, val
|
# for `storage` events
|
||||||
|
localStorage.setItem key, val
|
||||||
GM_setValue key, val
|
GM_setValue key, val
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user