Begin working on Chrome's storage API.
Let's start easy with $.delete.
This commit is contained in:
parent
48457f2712
commit
1b9c606f11
26
lib/$.coffee
26
lib/$.coffee
@ -202,8 +202,8 @@ $.extend $,
|
|||||||
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
||||||
|
|
||||||
<% if (type === 'crx') { %>
|
<% if (type === 'crx') { %>
|
||||||
delete: (key) ->
|
delete: (keys) ->
|
||||||
localStorage.removeItem g.NAMESPACE + key
|
chrome.storage.sync.remove keys
|
||||||
get: (key, defaultVal) ->
|
get: (key, defaultVal) ->
|
||||||
if val = localStorage.getItem g.NAMESPACE + key
|
if val = localStorage.getItem g.NAMESPACE + key
|
||||||
JSON.parse val
|
JSON.parse val
|
||||||
@ -221,10 +221,14 @@ do ->
|
|||||||
# To access the storage object later, keep a reference
|
# To access the storage object later, keep a reference
|
||||||
# to the object.
|
# to the object.
|
||||||
{scriptStorage} = opera
|
{scriptStorage} = opera
|
||||||
$.delete = (key) ->
|
$.delete = (keys) ->
|
||||||
key = g.NAMESPACE + key
|
unless keys instanceof Array
|
||||||
localStorage.removeItem key
|
keys = [keys]
|
||||||
delete scriptStorage[key]
|
for key in keys
|
||||||
|
key = g.NAMESPACE + key
|
||||||
|
localStorage.removeItem key
|
||||||
|
delete scriptStorage[key]
|
||||||
|
return
|
||||||
$.get = (key, defaultVal) ->
|
$.get = (key, defaultVal) ->
|
||||||
if val = scriptStorage[g.NAMESPACE + key]
|
if val = scriptStorage[g.NAMESPACE + key]
|
||||||
JSON.parse val
|
JSON.parse val
|
||||||
@ -238,9 +242,13 @@ do ->
|
|||||||
scriptStorage[key] = val
|
scriptStorage[key] = val
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
delete: (key) ->
|
delete: (key) ->
|
||||||
key = g.NAMESPACE + key
|
unless keys instanceof Array
|
||||||
localStorage.removeItem key
|
keys = [keys]
|
||||||
GM_deleteValue key
|
for key in keys
|
||||||
|
key = g.NAMESPACE + key
|
||||||
|
localStorage.removeItem key
|
||||||
|
GM_deleteValue key
|
||||||
|
return
|
||||||
get: (key, defaultVal) ->
|
get: (key, defaultVal) ->
|
||||||
if val = GM_getValue g.NAMESPACE + key
|
if val = GM_getValue g.NAMESPACE + key
|
||||||
JSON.parse val
|
JSON.parse val
|
||||||
|
|||||||
@ -331,8 +331,7 @@ Settings =
|
|||||||
innerHTML: "<button>Hidden: #{hiddenNum}</button><span class=description>: Clear manually hidden threads and posts on /#{g.BOARD}/."
|
innerHTML: "<button>Hidden: #{hiddenNum}</button><span class=description>: Clear manually hidden threads and posts on /#{g.BOARD}/."
|
||||||
$.on $('button', div), 'click', ->
|
$.on $('button', div), 'click', ->
|
||||||
@textContent = 'Hidden: 0'
|
@textContent = 'Hidden: 0'
|
||||||
$.delete "hiddenThreads.#{g.BOARD}"
|
$.delete ["hiddenThreads.#{g.BOARD}", "hiddenPosts.#{g.BOARD}"]
|
||||||
$.delete "hiddenPosts.#{g.BOARD}"
|
|
||||||
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
|
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
|
||||||
export: ->
|
export: ->
|
||||||
now = Date.now()
|
now = Date.now()
|
||||||
|
|||||||
@ -14,5 +14,8 @@
|
|||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
}],
|
}],
|
||||||
"homepage_url": "<%= meta.page %>",
|
"homepage_url": "<%= meta.page %>",
|
||||||
"minimum_chrome_version": "25"
|
"minimum_chrome_version": "25",
|
||||||
|
"permissions": [
|
||||||
|
"storage"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user