Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run site-specific user scripts in Safari? [closed]

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?

like image 965
Lucas peret Avatar asked Apr 30 '15 23:04

Lucas peret


1 Answers

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:

  1. Create an extension folder—open Extension Builder, click +, choose New Extension, give it a name and location.
  2. Drag your script file into the extension folder.
  3. Click New Script under Injected Extension Content in Extension Builder, as illustrated in Figure 10-1:

Figure 10-1  Specifying injected content

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:

extension website access

This is what you want to use to blacklist/whitelist sites.

like image 176
royhowie Avatar answered Sep 28 '22 23:09

royhowie