User scripts can enhance the functionality of the original web pages or remove some of the restrictions on the web pages.
User scripts are compact, flexible and easy to use. They can easily expand the browser function.
In order to be compatible with bookmarklet, the following grammar is also legitimate.
Enter user script management to add a script to your browser (Browser settings>>Browser scripts>>New script)
User scripts are automatically executed when the page is loaded by default. Of course, you can set the [user script scope](#User script scope) to determine whether the script takes effect globally or under a specific domain name.
In addition to this, scripts can also be set to be manually triggered by extension points on the browser UI. There are three general extension points: “page tool menu”, “long press menu”, “main menu”.
After setting menu extension point as script execution mode, new menu options are automatically generated as script execution entry in the corresponding menu, as shown in the following figure.
When you set the script to be executed automatically, we can decide whether the script will take effect globally or at a specific site by setting the scope of the user script. The following is the representation of scoping rules.
Match all sites
Match exactly the specific domain name, the script only executes under the www.example.com domain name
Any of the above can be used to match a site whose main domain name is example.com.
Match multiple domain names, split by “,”
Meta data, which is a descriptive mark placed at the head of the script, is used to describe and set the script. Below are some metadata description keywords supported by the XBrowser.
Used to name the script
Declare the script author
Used to describe the script
This tag can have multiple lines to describe the scope of the script.
Similar to the @include tag, there can be multiple lines. Used to describe script scope
This tag is used to exclude some domain names and is usually used to tell global scripts not to execute under a specific domain name.
This is also a multi-line tag that specifies that the script needs to reference a third-party library or script.
By default, the script will not be executed until the page is loaded. We can use “@run-at” to control the execution time of the script. Refer to the optional values below.
- document-start Tell the script to execute before building the DOM tree.
- document-end Tell the script to execute after the DOM tree is built.
- document-idel Tell the browser script to execute after the page is loaded.
These are the metadata tags currently supported by XBrowser. These tags are compatible with the metadata tags of some tampermonkey scripts. See here
for more details.
Below is an example of a script with metadata that depend on a third-party component, VConsole
// @name Developer debug tool
This is currently the world’s largest user script sharing site. The scripts compatible with mobile browsers in the site can be installed directly in the XBrowser.
This is the XBrowser officially maintained user script sharing site, where the scripts are all shared from users. Usually, it is a script suitable for mobile browsers after user testing. It is recommended that users search for the required scripts here.