What is a user script?
A user script is a piece of user-defined javascript code that can be run automatically during page loading or can be injected into the current page under certain conditions. User scripts can be used to enhance the functionality of the original web page or to remove some web page limitations, thus making the original web page a better user experience.
User scripts are small, flexible and easy to use, and can be used to extend the browser functionality very easily. Some regular browser functions can be implemented in the form of user scripts, such as reading mode, page translation, night mode, etc.
Categories of user scripts
Based on the characteristics of user scripts we can broadly classify user scripts into two categories, which we call normal user scripts and Greasemonkey scripts
Normal Scripts
A normal user script is a piece of Javascript code that is loosely organized and does not require a specific development specification, as long as it conforms to the standard Javascript syntax, and is small, flexible and easy to use.
A Normal script is a piece of Javascript code that is loosely organized and does not require a specific development specification, as long as it follows the standard Javascript syntax, and is small, flexible and easy to use.
Here is the simplest normal user script
alert("Hello Word!"); |
Greasemonkey scripts
Greasemonkey originated as an extension on FireFox and later appeared Tampermonkey with wider support and better compatibility. We call scripts compatible with these two extensions collectively called Greasemonkey scripts
The following is the simplest GreaseMonkey script
// ==UserScript== |
Compared to normal scripts, we find that Grease Monkey scripts contain two parts, one is the file header consisting of metadata, and the other is the code body. The metadata tags define some information related to the script, such as version, name, third-party library dependencies, resource dependencies, execution permissions, and other information. In addition, the script manager also provides some advanced APIs to help developers achieve more efficient and convenient development. More information about metadata and APIs will be introduced in the User script API Reference.