
Userscripts Go deeper
- Tutorial
As mentioned in a previous article , user scripts are supported by all modern browsers . And even somehow supported in IE7 and higher .
In this article we will talk about browsers :
The quality of user script support is at a different level in different browsers. Best of all, user-script support is provided in the Firefox and Chrome browsers .
These browsers provide less user friendly interfaces for managing user scripts.
The most severe restrictions on user scripts are imposed by Chrome . But almost all of these restrictions are bypassed by packing the script into a simple extension . The details of this process will be discussed in the next article .
Now let's talk more about user script support in individual browsers.
Mozilla Firefox supports user scripts 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 following information is applicable primarily to GreaseMonkey (this extension was the first).
Installation: user scripts are installed by simply dragging and dropping the script file into the browser.
Extensions: GreaseMonkey , Scriptish .
Management: user scripts 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 user scripts.
Of the most requested features that the GM API provides, it is worth mentioning:
Learn more about the GM API and GreaseMoneky functionality at http://wiki.greasespot.net .
Historically, all user scripts were written for the Firefox browser precisely because of the availability of a convenient plug-in.
This is due to the fact that all browsers that support user scripts additionally follow the basic rules of the GreaseMonkey metadata parsing specification .
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 a 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 “bikes” of my 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 only have to modify one file; the user needs only 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!
Google Chrome supports native scripts, i.e. No plugins / extensions required. It is possible ( sometimes necessary ) to pack a user script into an extension.
Installation: user scripts are installed by simply dragging and dropping the script file into the browser.
Extensions: not needed. There is an extension Tampermonkey , which simplifies the work with scripts.
Management: user scripts, like extensions, can be disabled and deleted ( Settings -> Tools -> Extensions ).
Features:
An extension is an archive packaged by the browser itself ( Settings -> Tools -> Extensions -> Pack extension ).
In addition to the user script file, the extension must contain:
Packing a user script into an extension circumvents many of the limitations Google Chrome places on user scripts.
Important: in fact, extension and user script are different concepts. And if you approach the issue strictly, it’s worth talking about developing simple extensions for Chrome.
In the case when a user script requires non-standard, “heavy” functionality, it requires packaging in an extension.
To pack a user script into an extension, you need to do additional actions once . All subsequent development will be carried out within the framework of the concept of a single file .
Opera natively supports user scripts, but does not provide a user-friendly 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-configured user scripts folder. Its location can be set in the browser settings: Settings -> General Settings -> Advanced -> Content -> Customize JavaScript . The user script folder must not contain spaces .
Management: user scripts can be disabled by deleting or moving the script file from the user scripts folder.
Features:
IE7, IE8, IE9 support user scripts when using the Trixie plugin .
In addition, there is a more advanced IE7Pro plugin . In addition to supporting IE7Pro yuzerskriptov there are many otherdemon of useful features.
Important: If you do not disable additional "Pribluda" in IE7Pro, then the plugin can pretty much slow down the browser, especially on heavy pages.
Extensions: Trixie , IE7Pro .
Installation: user scripts are installed in the Trixie user scripts folder (C: / Program Files / Bhelpuri / Trixie / Scripts) or IE7Pro (C: / Program Files / IEPro / userscripts) .
Control:Each plugin has a user interface for managing user scripts.
Features:
As you can see, things are lousy with running scripts in IE. 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: Given the above, I always suggest that my users use Trixie .
Unfortunately, I was not able to work with this browser. I will be glad to any clarification in the comments!
Rumor has it that Safari needs a SIMBL and a GreaseKit plugin .
Due to the lack of support for user scripts in less popular browsers and mobile browsers, user scripts will have to be provided as a bookmarklet .
Accordingly, metadata is not needed in this case, and the bookmarklet will have to be launched manually after each refresh.
If you adhere to the concept of a single file , then the creation process goes along this path:
List of articles:
In this article we will talk about browsers :
- Limitations
- Problems
- Extensions to run user scripts
- Setting user scripts
A few words about the engines
The quality of user script support is at a different level in different browsers. Best of all, user-script support is provided in the Firefox and Chrome browsers .
These browsers provide less user friendly interfaces for managing user scripts.
The most severe restrictions on user scripts are imposed by Chrome . But almost all of these restrictions are bypassed by packing the script into a simple extension . The details of this process will be discussed in the next article .
Now let's talk more about user script support in individual browsers.
Support in Firefox
Mozilla Firefox supports user scripts 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 following information is applicable primarily to GreaseMonkey (this extension was the first).
Installation: user scripts are installed by simply dragging and dropping the script file into the browser.
Extensions: GreaseMonkey , Scriptish .
Management: user scripts can be disabled and deleted in the menu added by extensions.
Features:
- There is a powerful GM API library.
- Replaced by the "native" global window object .
- Objects of the native window, for example window.page_defined_var , are accessible through the unsafe link unsafeWindow .
- Cross-domain requests are available through the XmlHttpRequest interface.
- An analogue of globalStorage is available.
- The ability to connect third-party libraries (for example, jQuery) is available.
- Due to the security of the GreaseMonkey plugin, some features require specific hacks .
For example, running GM_setValue (...) in the ajax request handler may cause an access error to the GM API methods. To handle this situation, a construction of the form setTimeout (function () {GM_setValue (...)}, 0) is used . - There is no possibility of debugging user scripts. Even Firebug will not help here.
GreaseMonkey adds the so-called GM API - a set of javascript functions that add functionality to user scripts.
Of the most requested features that the GM API provides, it is worth mentioning:
- The object of the "native window" of the unsafeWindow page (allows you to replace functions on the page, use existing libraries on the page)
- Cross domain HttpXmlRequest: GM_xmlhttpRequest
- Analog of globalStorage (localStorage without domain binding): GM_setValue , GM_getValue and GM_deleteValue
Learn more about the GM API and GreaseMoneky functionality at http://wiki.greasespot.net .
Historically, all user scripts were written for the Firefox browser precisely because of the availability of a convenient plug-in.
This is due to the fact that all browsers that support user scripts additionally follow the basic rules of the GreaseMonkey metadata parsing specification .
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 a 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 “bikes” of my 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 only have to modify one file; the user needs only 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, i.e. No plugins / extensions required. It is possible ( sometimes necessary ) to pack a user script into an extension.
Installation: user scripts are installed by simply dragging and dropping the script file into the browser.
Extensions: not needed. There is an extension Tampermonkey , which simplifies the work with scripts.
Management: user scripts, like extensions, can be disabled and deleted ( Settings -> Tools -> Extensions ).
Features:
- Document.frames [i] .parent is not available ( allowed in the extension ).
- Objects of the native window are not available, for example window.page_defined_var (it will not be possible to replace the page functions, JSONP also disappears in the user script)
- Cross-domain requests are not available ( allowed in the extension )
- unsafeWindow is available but does not carry GM API functionality.
- Convenient native debug of user scripts and extensions.
An extension is an archive packaged by the browser itself ( Settings -> Tools -> Extensions -> Pack extension ).
In addition to the user script file, the extension must contain:
- manifest.json - extension description file. User metric analogue metadata.
- background.html - file of the "background page" of the extension. Gives access to the extension API through calling chrome.extension methods . *
Packing a user script into an extension circumvents many of the limitations Google Chrome places on user scripts.
Important: in fact, extension and user script are different concepts. And if you approach the issue strictly, it’s worth talking about developing simple extensions for Chrome.
In the case when a user script requires non-standard, “heavy” functionality, it requires packaging in an extension.
To pack a user script into an extension, you need to do additional actions once . All subsequent development will be carried out within the framework of the concept of a single file .
Support in Opera
Opera natively supports user scripts, but does not provide a user-friendly 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-configured user scripts folder. Its location can be set in the browser settings: Settings -> General Settings -> Advanced -> Content -> Customize JavaScript . The user script folder must not contain spaces .
Management: user scripts can be disabled by deleting or moving the script file from the user scripts folder.
Features:
- User scripts are run "as is", without turning into a closure, thereby clogging the global scope of the window .
- Objects of the native window are available, for example window.page_defined_var .
- Opera specific browser events available, such as BeforeScript .
- Cross-domain requests are not available ( Bypassed using special events )
- unsafeWindow is unavailable.
- Scripts are run in alphabetical order.
Support in IE
IE7, IE8, IE9 support user scripts when using the Trixie plugin .
In addition, there is a more advanced IE7Pro plugin . In addition to supporting IE7Pro yuzerskriptov there are many other
Important: If you do not disable additional "Pribluda" in IE7Pro, then the plugin can pretty much slow down the browser, especially on heavy pages.
Extensions: Trixie , IE7Pro .
Installation: user scripts are installed in the Trixie user scripts folder (C: / Program Files / Bhelpuri / Trixie / Scripts) or IE7Pro (C: / Program Files / IEPro / userscripts) .
Control:Each plugin has a user interface for managing user scripts.
Features:
- User scripts are run "as is", without turning into a closure, thereby clogging the global scope of the window .
- Objects of the native window are available, for example window.page_defined_var .
- Cross-domain requests are not available (You can get around in ways similar to those used in javascript development: JSONP, easyXDM xdr, etc. )
- unsafeWindow is unavailable.
- Both Trixie and IEPro have a script loading model different from the GreaseMonkey model. Scripts do not restart when a page is refreshed via Ctrl + R or Ctrl + F5 . In addition, scripts are loaded by window.onLoad .
- In order for Trixie to see the script, the script must have metadata and must have the @namespace directive (see the previous article ) .
- In order for IE7Pro to see the script, the script must have the extension .ieuser.js .
- Both plugins have problems running in IE9 under Windows 7x64.
I encountered more reports about the unreleased IE7Pro.
As you can see, things are lousy with running scripts in IE. 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: Given the above, I always suggest that my users use Trixie .
Support in Safari
Unfortunately, I was not able to work with this browser. I will be glad to any clarification in the comments!
Rumor has it that Safari needs a SIMBL and a GreaseKit plugin .
Support in Mobile Safari and other browsers
Due to the lack of support for user scripts in less popular browsers and mobile browsers, user scripts will have to be provided as a bookmarklet .
Accordingly, metadata is not needed in this case, and the bookmarklet will have to be launched manually after each refresh.
Lastly
If you adhere to the concept of a single file , then the creation process goes along this path:
- Take the template.
- Add
watercode and metadata. - Create a folder and files for the Chrome extension.
- We pack the extension for Chrome, rename the file for IE7Pro.
- We distribute user script / extension to users.
- ...
- We fix
handsbugs. - Goto 4
List of articles:
- Learning to write userscripts
- » Userscripts. We go deeper.
- Userscripts We pack a user script for Chrome
- Usersctripts. Cross domain requests