Answer the question
In order to leave comments, you need to log in
How to properly implement modules in userscripts (userscript)?
I did not find any information on the Web about how userscript projects should be developed. Obviously, any project larger than HelloWorld should have a modular structure internally, especially if the same modules are used in many different projects and at the same time are themselves (before) developed.
https://wiki.greasespot.net/Third-Party_Libraries - all this is not the same, it only applies to third-party libraries that are already on the Web, but not modules of their own project in development.
I just started writing a small automation of actions on one site and I already have a bunch of scripts, consisting of 90% of the general code, which I modify somewhere, I forget to copy the updated one somewhere ... in general, before I start, I already fell into the hell of copy-pasting, where all violators of the DRY principle fall.
Answer the question
In order to leave comments, you need to log in
Это же обычное JS приложение. Соответственно работать как с JS.
Любой фреймворк использовать и т.п.
Структура соответствующая.
Move the general code to the "library", for example, in the form:
window.unsafeWindow = window.unsafeWindow || window;
const w = unsafeWindow;
w.Lib = {
Foo: function(){},
...
}
w.Lib.Bar = {
...
}
// @run-at document-start
// @run-at document-end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question