As I wrote in the introductory article about GreaseMonkey, dissatisfied with the lack of an update system for user scripts, we took the issue into development. A few days later, the solution materialized into a kind of integrated tool, which we called “The Generator Script Template Generator for GreaseMonkey”. Its interface is available at
tbms.ru/greasemonkey/generatorThe generator creates a custom script, in which, besides all the necessary meta-information, a
GMHelper object is
built in , which implements the update system and several other useful functions.
')
The main function of
GMHelper is script update. All the functionality is already built into the template, the only thing you need to do is specify a valid link to the location of the JS file with the script (through the generator) and follow the version numbering in the development process. Once in 24 hours,
GMHelper downloads the first kilobyte from the JS file by reference and looks to see if the version has changed, in case of a change, it offers to download. If you refuse, it leaves you alone for another 24 hours.
In the course of development,
GMHelper has a few more useful, in our opinion, functions. First, we wrapped GM_getValue / GM_setValue in the
GMHelper shell
. GetValue / setValue. This solves two problems: the GM availability check (if you are doing the cross-browser script) and the conversion of unsupported types during writing (an attempt to write the Date via GM_setValue causes an error).
Well, for the order, we put the JS namespace generator getNamespace, which accepts the required window (hello unsafeWindow), and an array of names for nested namespaces. Consider an example:
GMHelper.getNamespace(window, ['Weborama', 'InlinePlayer']);
will create the Weborama.InlinePlayer
namespace of the window GreaseMonkey.
In conclusion, I want to say that we will be glad to any comments and suggestions, and, in turn, we hope that our template will be useful.