5

Instead having 3 versions of my browser's userscripts:

  1. local-draft
  2. local-Greasemonkey
  3. Github

I want to have only 1 script instance in Github.

I need a way to import the content of the script, which is being edited communally in Github, directly from Github to Greasemonkey.

Thus, changes made to the script in Github will automatically affect all users using the script in their browsers, without them needing to copy changes manually with each new update.

Know a way to do so? Please limit your answer to the best 1 or 2 ways you know.

Notes:

  • Of course I backup my PC usually, including GitHub material.
terdon
  • 98,183
  • 15
  • 197
  • 293

1 Answers1

6

There's two parts to your question.


The first is loading a script for installation directly from a GitHub repository or a GitHub GIST.

Both GitHub repositories and GISTs permit you to get a "Raw" object link which points to the object itself and serves that object up directly, as plain text if possible, in the web browser. Userscripts are usually picked up properly with these "Raw" URLs. You can get the raw URL by clicking the "Raw" button on an individual item in the GIST, or when you're viewing a specific object in the GitHub repository. That "raw link" is then what you can distribute for installation purposes.


The second part is setting the update and download fields within the userscript to point to the same raw link that you got above, in order to let GreaseMonkey / TamperMonkey autoupdate.

There are many scripts that do this. I'm going to use an example from the Charcoal Team's Userscripts repository, called Flag Dialog Smokey Controls, aka FDSC, which has a good example of such a configuration.

A userscript has a header section, which defines specifics of the user script, such as the name of the script, its version number, contributors, sites that it is enabled for, and other fields. There are two fields here which are highly relevant to the 'download' and 'update' components that you're after - @updateURL, and @downloadURL. Set these fields in your // ==UserScript== comment/header section to the raw link that I refer to in the first section. Then, Greasemonkey/Tampermonkey will interpret the update URLs appropriately, and update accordingly when you increment the 'version' in the userscript header section.

Note that FDSC uses two scripts for this, one for the actual update detection and the other for the actual download location for where to get the updated version:

// @updateURL   https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fdsc/fdsc.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fdsc/fdsc.user.js

I believe you can use the same link though for these. (I haven't tested this though)

Thomas Ward
  • 72,494
  • 30
  • 173
  • 237
  • Note that after I posted this, I also cleaned up comments which basically discussed what this answer discusses from the question itself. In case anyone cares. – Thomas Ward Mar 13 '18 at 14:48