Skip to content

Commit 8849baf

Browse files
committed
make GM.info/GM_info an object
1 parent 426dcf1 commit 8849baf

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,11 @@ Userscripts currently supports the following api methods. All methods are asynch
204204
- "synchronous' version of `GM.setClipboard`
205205
- the setClipboard function runs in the background script, requires a promise to send message from content script to background to facilitate writing to the clipboard, thus no real synchronous function available
206206
- returns `undefined`
207-
- `GM.info()` && `GM_info()`
208-
- both methods are **synchronous**
207+
- `GM.info` && `GM_info`
209208
- is available without needing to add it to `@grant`
210-
- returns an object containing information about the running userscript
209+
- an object containing information about the running userscript
211210
- `scriptHandler: String` - returns `Userscripts`
212-
- `version: String` - the version of Userscripts
211+
- `version: String` - the version of Userscripts app
213212
- `scriptMetaStr: String` - the metablock for the currently running script
214213
- `script: Object` - contains data about the currently running script
215214
- `description: String`
@@ -224,7 +223,7 @@ Userscripts currently supports the following api methods. All methods are asynch
224223
- `requires: [String]`
225224
- `resources: [String]` - *currently not implemented*
226225
- `runAt: String`
227-
- `version: String` - *userscript version value*
226+
- `version: String` - *the userscript version value*
228227
- `GM.xmlHttpRequest(details)`
229228
- `details: Object`
230229
- the `details` object accepts the following properties

extension/Userscripts Extension/Resources/content.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ function injectJS(filename, code, scope, timing, grants, fallback) {
6161
const us_info = {filename: filename, info: scriptData, uid: uid};
6262
api += `\nconst us_info = ${JSON.stringify(us_info)}`;
6363
// all scripts get acces to GM.info and GM_info
64-
api += `\n${us_getInfo}`;
65-
api += "\nconst GM_info = us_getInfo;\n";
66-
gmVals.push("info: us_getInfo");
64+
api += "\nconst GM_info = us_info.info;\n";
65+
gmVals.push("info: us_info.info");
6766
grants.forEach(grant => {
6867
if (grant === "GM.openInTab") {
6968
api += `\n${us_openInTab}`;
@@ -402,11 +401,6 @@ function us_setClipboard(data, type) {
402401
});
403402
}
404403

405-
function us_getInfo() {
406-
// eslint-disable-next-line no-undef -- us_info var accessible to the function at runtime
407-
return us_info.info;
408-
}
409-
410404
function us_setClipboardSync(data, type) {
411405
// there's actually no sync method since a promise needs to be sent to bg page
412406
// however make a dummy sync method for compatibility

0 commit comments

Comments
 (0)