mock-violentmonkey
Version:
Mock violentmonkey's globals for testing userscripts
55 lines • 1.48 kB
JavaScript
import process from 'node:process';
import { GM_addStyle } from './add-style.js';
import { GM_setClipboard } from './clipboard.js';
import { GM_info } from './info.js';
import { GM_notification } from './notification.js';
import { GM_openInTab } from './open-in-tab.js';
import { GM_getResourceURL } from './resource.js';
import { GM_deleteValue, GM_getValue, GM_listValues, GM_setValue, } from './storage.js';
import { GM_xmlhttpRequest } from './xmlhttprequest.js';
const makeFunctionAsync = (function_) => async (...arguments_) => {
await new Promise(resolve => {
process.nextTick(resolve);
});
return function_(...arguments_);
};
const GM = Object.defineProperties({}, {
setValue: {
value: makeFunctionAsync(GM_setValue),
},
getValue: {
value: makeFunctionAsync(GM_getValue),
},
listValues: {
value: makeFunctionAsync(GM_listValues),
},
deleteValue: {
value: makeFunctionAsync(GM_deleteValue),
},
addStyle: {
value: GM_addStyle,
},
getResourceURL: {
value: GM_getResourceURL,
},
notification: {
value: GM_notification,
},
setClipboard: {
value: GM_setClipboard,
},
openInTab: {
value: GM_openInTab,
},
xmlHttpRequest: {
value: GM_xmlhttpRequest,
},
info: {
get: GM_info,
},
});
export { GM };
Object.defineProperty(globalThis, 'GM', {
value: GM,
});
//# sourceMappingURL=gm.js.map