I created a javascript user script for one website. I would like that my navigator detect automatically when I am on this website and execute the script.
Is it possible to run an injected script on a specific site only?
Yes, this is possible. Apple has written up a guide. Note the bolded part towards the end.
Adding a Script
To add an injected script, follow these steps:
- Create an extension folder—open Extension Builder, click +, choose New Extension, give it a name and location.
- Drag your script file into the extension folder.
- Click New Script under Injected Extension Content in Extension Builder, as illustrated in Figure 10-1:
You can choose to inject your script as a Start Script or an End Script. An End Script executes when the DOM is fully loaded—at the time the onload attribute of a body element would normally fire. Most scripts should be injected as End Scripts. A Start Script executes when the document has been created but before the webpage has been parsed. If your script blocks unwanted content it should be a Start Script, so it executes before the page displays.
Choose your script file from the pop-up menu. You can have both Start and End Scripts. You can have more than one script of each type.
In order for your scripts to be injected, you must specify either Some or All website access for your extension. You can have your script apply to a single webpage, all webpages, or only certain webpages—pages from certain domains, for example. For details, see the description of whitelists and blacklists in Access and Permissions.
From that last link (this one), this is the important picture:
This is what you want to use to blacklist/whitelist sites.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With