[Feature] `@require-local` for loading other util userscripts
Currently, it has @require for loading the remote JavaSctipt code.
I would like to be able to load a "local" JS code from another util/lib userscript.
For example, like User JavaScript and CSS does.
I would very useful when you have a lot of tiny userscripts with the same util code. And for 3rd-party libraries too — no need to rely on a remote URL which may die or the content is changed.
For example, a script with the proposed @require-id:
// ==UserScript==
// @name JS Utils
// @version 1.0
// @require-id utils.common
// ==/UserScript==
function sleep(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
function addCSS(css) {
const styleElem = document.createElement("style");
styleElem.textContent = css;
document.body.append(styleElem);
return styleElem;
}(The script with @require-id should be used only for @requireing in other scripts.)
and the main code:
// ==UserScript==
// @name Local Require Example
// @match https://example.org/*
// @grant none
// @require utils.common
// ==/UserScript==
!async function main() {
for (const i in [1, 2, 3]) {
console.log(i);
await sleep(1000);
}
}();Suggestions for the module script: @require-id / @require-local-id / @id / @script-id.
Suggestions for the main script: @require id/ @require local id/ @require local id remote https://example.com/fallback.js.
Source: violentmonkey/violentmonkey