📜 ⬆️ ⬇️

Userscripts. Go deep

As mentioned in the previous article , userscripts are supported by all modern browsers . And even somehow supported in IE7 and higher .

In this article we will talk about browsers :



Couple of words about engines


The quality of user scripts support is on a different level in different browsers. Best of all, support for userscripts is done in Firefox and Chrome browsers.
These browsers provide less user-friendly interfaces for managing userscripts.
')
The most severe restrictions on user scripts are imposed by Chrome . But almost all of these limitations cost the packaging of the script into a simple extension . Details of this process will be discussed in the next article .

Now let's talk more about the support of userscripts in individual browsers.

Firefox Support


Mozilla Firefox supports userscripts after installing the GreaseMonkey extension (in Russian slang - monkey ) or Scriptish .
After installing the extensions, firefox gets a truly powerful support for user scripts.
The information discussed below applies primarily to GreaseMonkey (this extension was the first).

Installation: userscripts are installed by simply dragging the script file into the browser.
Extensions: GreaseMonkey , Scriptish .
Management: userscripts can be disabled and deleted in the menu added by extensions.
Features:

GreaseMonkey adds the so-called GM API - a set of javascript functions that add functionality to userscripts.
Of the most requested features that the GM API provides, it is worth mentioning:
  1. Object of the “native window” of the unsafeWindow page (allows replacing functions on the page, using the existing libraries on the page)
  2. Cross Domain HttpXmlRequest: GM_xmlhttpRequest
  3. Analog globalStorage (localStorage without binding to the domain): GM_setValue , GM_getValue and GM_deleteValue

Learn more about the GM API and GreaseMoneky functionality at http://wiki.greasespot.net .

Historically, all userscripts were written under the Firefox browser precisely because of the presence of a convenient plugin.
This is due to the fact that all browsers that support user scripts additionally follow the basic rules of the GreaseMonkey specification for parsing metadata .
This means that all scripts that were written under GreaseMonkey will be installed and run in browsers that support user scripts (with a minimum of modifications).

Unfortunately, no browser other than Firefox provides the GM API. This sad fact forces us to use GM API emulations through extensions or additional user scripts.

In the case of developing a user script from scratch, I consider it preferable to abandon the GM API emulation and use the “bikes” of our own production. This allows you to reduce the number of user script dependencies, which, in turn, allows you to develop within the framework of the concept of a single file : you will need to modify only one file; the user only needs one file to run the user script.

The concept of a single file can significantly reduce the complexity of support and cross-browser development of user scripts!

Chrome support


Google Chrome supports native scripts natively, i.e. does not require installation of plug-ins / extensions. It is possible ( sometimes necessary ) to pack a user script into an extension.

Installation: userscripts are installed by simply dragging the script file into the browser.
Extensions: not needed. There is an extension Tampermonkey , which simplifies working with scripts.
Management: userscripts, as well as extensions, can be disabled and deleted ( Settings -> Tools -> Extensions ).
Features:

An extension is an archive packed by the browser itself ( Settings -> Tools -> Extensions -> Package Extension ).
In addition to the user script file, the extension should contain:

Packing user scripts in an extension allows you to bypass many of the restrictions imposed by Google Chrome on user scripts.

Important: in fact, the extension and user scripts are different concepts. And if you approach the issue strictly, it is worth talking about the development of simple extensions for Chrome.
In the case when the user script requires non-standard, "heavy" functionality, it requires packing in the extension.
To pack a user script into an extension, you need to do additional steps once . All subsequent development will be carried out within the framework of the concept of a single file .

Opera support


Opera supports native scripts natively, but does not provide any friendly user interface for managing scripts. Such an interface is available in the UJS Manager extension.

Extensions: UJS Manager , UserJS Manager .
Installation: user scripts are installed in a user-defined folder of user scripts. Its location can be set in the browser settings: Settings -> General Settings -> Advanced -> Content -> Customize JavaScript . The folder with userscripts should not contain spaces .
Management: user scripts can be disabled by deleting or moving the script file from the user scripts folder.
Features:

IE support


IE7, IE8, IE9 support user scripts when using the Trixie plugin.
In addition, there is the more advanced IE7Pro plugin. In addition to user scripts, IE7Pro has many other useful features.

Important: If you do not disable additional “pribluda” in IE7Pro, then the plugin can significantly slow down the browser, especially on heavy pages.

Extensions: Trixie , IE7Pro .
Installation: userscripts are installed in the Trixie user scripts folder (C: / Program Files / Bhelpuri / Trixie / Scripts) or IE7Pro (C: / Program Files / IEPro / userscripts) .
Management: each plug-in has a user interface for managing userscripts.
Features:


As you can see, with the launch of the scripts in IE, things are lousy. It remains to be glad that such an opportunity exists at all.

Important: Both plugins can exist in the system at the same time, without interfering with each other.

Important: Considering the above, I always suggest my users to use Trixie .

Safari Support


Unfortunately, I was not able to work with this browser. I will be glad to any explanations in the comments!
Rumor has it that Safari needs SIMBL and GreaseKit plugin.

Support in Mobile Safari and other browsers


Due to the lack of support for userscripts in less popular browsers and mobile browsers, userscripts will have to be provided in the form of a bookmarklet .
Correspondingly, in this case, metadata is not needed, and the bookmarklet will have to be run by hand after each refresh.

Lastly



If you stick to the concept of a single file , then the process of creation follows this path:
  1. Take the template.
  2. Add water code and metadata.
  3. Create a folder and files for the Chrome extension.
  4. We pack the extension for Chrome, rename the file for IE7Pro.
  5. We distribute user scripts / extensions to users.
  6. ...
  7. We fix hands bugs.
  8. Goto 4



List of articles:
  1. Learning to write userscript
  2. » Userscripts. Deepen.
  3. Userscripts. We pack user scripts for Chrome
  4. Usersctripts. Cross Domain Queries

Source: https://habr.com/ru/post/129454/


All Articles