sangoko
sangoko

Reputation: 351

Including code from a URL into a Greasemonkey script to use it as the script?

Say I have a repository on GitHub with 3 files:

  1. myGreasemonekyScript.js
  2. readme.md
  3. license.md

myGreasemonekyScript.js stores a Greasemonkey script:

// ==UserScript==
// @name        facebook
// @namespace   nms
// @include     http://*.example.com/*
// @include     https://*.example.com/*
// @version     1
// @grant       none
// ==/UserScript==

// The rest of the script...

Is there a way just to call it from Greasemonkey so that the local Greasemonkey script file will have only an inclusion (an include) of the remote version that sits in GitHub?

Note: The reason I'd like to do that is minimalism, instead having two version localy (the GM script file and a backup in another folder), I would like to center the code editing in one place, without the need to copy changes between each files, each time anew.

Upvotes: 1

Views: 1652

Answers (1)

Tomáš Zato
Tomáš Zato

Reputation: 53139

I can see four options to do this:

1. Just install the script from github

You will need to tweak the update interval.

All you need to do is to enter Raw view on github and greasemonkey will ask you to install the script. I created an example repository to demonstrate this.

After the script is installed, go into settings and set the auto updating to On: enter image description here

Further reading: How does user script updating work?

2. Append <script> tag

This is pretty obvious solution but unsuitable for production for security reasons. You can just append script tag to the document, linking your script on github.

3. @require command

This has the flaw that Greasemonkey downloads @require dependencies only once, so you'd need to change something (eg. ?random_number) in URL to force refresh after updating the script.

4. Use my refresher

I once made Node.js script that accepts path to userscript files anywhere on filesystem. It will then search those paths in process.env.appdata+"\\Mozilla\\Firefox\\Profiles\\ap7ptx7o.default\\gm_scripts" (you might need to alter this path) and every time you modify the refference path (the one in your GitHub repo), it will copy it to your userscripts folder.

Upvotes: 1

Related Questions