6

I need to host a userscript on an internal company website. How do I build the href so that Greasemonkey will install the userscript when the link is clicked?

I tried a simple <a href="user.js">Install Userscript</a> but Chrome and Firefox simply show the file source instead of installing the userscript.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Aaron Mclean
  • 83
  • 1
  • 6
  • Possible duplicate of [My Greasemonkey script won't install](http://stackoverflow.com/questions/9976157/my-greasemonkey-script-wont-install) – the8472 Oct 26 '16 at 21:01
  • @the8472, Not really a duplicate. That other guy was asking about a local cut-and-paste. IIRC, he was trying to make local changes to someone else's script, not host his own. – Brock Adams Oct 27 '16 at 06:20

1 Answers1

18

Your link should look like:

<a href="https://example.com/your_script.user.js">Click to install script X</a>
<small>(A userscript engine, like Tampermonkey, is required.)</small>

In order for your install link to work, the following conditions must be met:

  1. The filename must end in .user.js. Example: stack_exchange_edit_reasoner.user.js
  2. The browser must be running a compatible userscript extension. For example, Tampermonkey or Greasemonkey.
  3. The file must NOT be served with text/html content type. (You would have to tamper with your server's default settings for this to be an issue.)

Also, if you wish for automatic updates to work, the script should be served via an https link (or it gets complicated).

gekkedev
  • 562
  • 4
  • 18
Brock Adams
  • 90,639
  • 22
  • 233
  • 295