Preliminary support for Greasemonkey 4.
This commit is contained in:
parent
75ed8fe248
commit
4226a18a6d
@ -56,7 +56,12 @@
|
|||||||
"GM_listValues",
|
"GM_listValues",
|
||||||
"GM_addValueChangeListener",
|
"GM_addValueChangeListener",
|
||||||
"GM_openInTab",
|
"GM_openInTab",
|
||||||
"GM_xmlhttpRequest"
|
"GM_xmlhttpRequest",
|
||||||
|
"GM.getValue",
|
||||||
|
"GM.setValue",
|
||||||
|
"GM.deleteValue",
|
||||||
|
"GM.listValues",
|
||||||
|
"GM.xmlHttpRequest"
|
||||||
],
|
],
|
||||||
"min": {
|
"min": {
|
||||||
"chrome": "33",
|
"chrome": "33",
|
||||||
|
|||||||
@ -16,11 +16,14 @@
|
|||||||
"globals": {
|
"globals": {
|
||||||
"MediaError": false,
|
"MediaError": false,
|
||||||
"Set": false,
|
"Set": false,
|
||||||
|
"Promise": false,
|
||||||
|
"BroadcastChannel": false,
|
||||||
"GM_info": false,
|
"GM_info": false,
|
||||||
"cloneInto": false,
|
"cloneInto": false,
|
||||||
"unsafeWindow": false,
|
"unsafeWindow": false,
|
||||||
"chrome": false<%=
|
"chrome": false,
|
||||||
meta.grants.map(x => `,\n "${x}": false`).join('')
|
"GM": false<%=
|
||||||
|
meta.grants.filter(x => !/\./.test(x)).map(x => `,\n "${x}": false`).join('')
|
||||||
%><%=
|
%><%=
|
||||||
read('/tmp/declaration.js').match(/^var (.*);/)[1].split(', ').map(x => `,\n "${x}": true`).join('')
|
read('/tmp/declaration.js').match(/^var (.*);/)[1].split(', ').map(x => `,\n "${x}": true`).join('')
|
||||||
%><%=
|
%><%=
|
||||||
|
|||||||
@ -492,6 +492,46 @@ do ->
|
|||||||
# http://wiki.greasespot.net/Main_Page
|
# http://wiki.greasespot.net/Main_Page
|
||||||
# https://tampermonkey.net/documentation.php
|
# https://tampermonkey.net/documentation.php
|
||||||
|
|
||||||
|
if GM?.deleteValue?
|
||||||
|
|
||||||
|
$.syncChannel = new BroadcastChannel(g.NAMESPACE + 'sync')
|
||||||
|
|
||||||
|
$.on $.syncChannel, 'message', (e) ->
|
||||||
|
for key, val of e.data when (cb = $.syncing[key])
|
||||||
|
cb val, key
|
||||||
|
|
||||||
|
$.sync = (key, cb) ->
|
||||||
|
$.syncing[key] = cb
|
||||||
|
|
||||||
|
$.forceSync = ->
|
||||||
|
|
||||||
|
$.delete = (keys, cb) ->
|
||||||
|
unless keys instanceof Array
|
||||||
|
keys = [keys]
|
||||||
|
Promise.all(GM.deleteValue(g.NAMESPACE + key) for key in keys).then ->
|
||||||
|
items = {}
|
||||||
|
items[key] = undefined for key in keys
|
||||||
|
$.syncChannel.postMessage items
|
||||||
|
cb?()
|
||||||
|
|
||||||
|
$.get = $.oneItemSugar (items, cb) ->
|
||||||
|
keys = Object.keys items
|
||||||
|
Promise.all(GM.getValue(g.NAMESPACE + key) for key in keys).then (values) ->
|
||||||
|
for val, i in values when val
|
||||||
|
items[keys[i]] = JSON.parse val
|
||||||
|
cb items
|
||||||
|
|
||||||
|
$.set = $.oneItemSugar (items, cb) ->
|
||||||
|
Promise.all(GM.setValue(g.NAMESPACE + key, JSON.stringify(val)) for key, val of items).then ->
|
||||||
|
$.syncChannel.postMessage items
|
||||||
|
cb?()
|
||||||
|
|
||||||
|
$.clear = (cb) ->
|
||||||
|
GM.listValues.then (keys) ->
|
||||||
|
$.delete keys.map((key) -> key.replace g.NAMESPACE, ''), cb
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
# workaround for Firefox 53 issue
|
# workaround for Firefox 53 issue
|
||||||
$.currentValue = {}
|
$.currentValue = {}
|
||||||
$.GM_getValue = (key) ->
|
$.GM_getValue = (key) ->
|
||||||
@ -613,4 +653,5 @@ $.clear = (cb) ->
|
|||||||
try
|
try
|
||||||
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
||||||
cb?()
|
cb?()
|
||||||
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
@ -63,7 +63,7 @@ CrossOrigin =
|
|||||||
options.overrideMimeType = 'text/plain; charset=x-user-defined'
|
options.overrideMimeType = 'text/plain; charset=x-user-defined'
|
||||||
else
|
else
|
||||||
options.responseType = 'arraybuffer'
|
options.responseType = 'arraybuffer'
|
||||||
GM_xmlhttpRequest options
|
(GM?.xmlHttpRequest or GM_xmlhttpRequest) options
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
file: (url, cb) ->
|
file: (url, cb) ->
|
||||||
@ -99,7 +99,7 @@ CrossOrigin =
|
|||||||
return
|
return
|
||||||
callbacks[url] = [cb]
|
callbacks[url] = [cb]
|
||||||
<% if (type === 'userscript') { %>
|
<% if (type === 'userscript') { %>
|
||||||
GM_xmlhttpRequest
|
(GM?.xmlHttpRequest or GM_xmlhttpRequest)
|
||||||
method: "GET"
|
method: "GET"
|
||||||
url: url+''
|
url: url+''
|
||||||
onload: (xhr) ->
|
onload: (xhr) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user