Improve syntax Greasemonkey 4 APIs

This commit is contained in:
Jesús 2019-12-06 21:45:39 -05:00
parent f9412b3ba4
commit 09eea77390
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -1,23 +1,23 @@
/* /*
This helper script bridges compatibility between the Greasemonkey 4 APIs and This helper script bridges compatibility between the Greasemonkey 4 APIs and
existing/legacy APIs. Say for example your user script includes existing/legacy APIs. Say for example your user script includes
// @grant GM_getValue // @grant GM_getValue
And you'd like to be compatible with both Greasemonkey 3 and Greasemonkey 4 And you'd like to be compatible with both Greasemonkey 3 and Greasemonkey 4
(and for that matter all versions of Violentmonkey, Tampermonkey, and any other (and for that matter all versions of Violentmonkey, Tampermonkey, and any other
user script engine). Add: user script engine). Add:
// @grant GM.getValue // @grant GM.getValue
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
And switch to the new (GM-dot) APIs, which return promises. If your script And switch to the new (GM-dot) APIs, which return promises. If your script
is running in an engine that does not provide the new asynchronous APIs, this is running in an engine that does not provide the new asynchronous APIs, this
helper will add them, based on the old APIs. helper will add them, based on the old APIs.
If you use `await` at the top level, you'll need to wrap your script in an If you use `await` at the top level, you'll need to wrap your script in an
`async` function to be compatible with any user script engine besides `async` function to be compatible with any user script engine besides
Greasemonkey 4. Greasemonkey 4.
(async () => { (async () => {
let x = await GM.getValue('x'); let x = await GM.getValue('x');
@ -101,7 +101,6 @@ Object.entries({
} }
}); });
Object.entries({ Object.entries({
'GM_addStyle': 'addStyle', 'GM_addStyle': 'addStyle',
'GM_deleteValue': 'deleteValue', 'GM_deleteValue': 'deleteValue',