将 URL 中的代码包含到 Greasemonkey 脚本中以将其用作脚本?

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

假设我在 GitHub 上有一个包含 3 个文件的存储库:

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

myGreasemonekyScript.js 存储一个 Greasemonkey 脚本:

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

// The rest of the script...

有没有办法从 Greasemonkey 调用它,这样 local Greasemonkey 脚本文件将只包含位于 GitHub?

注意:我想这样做的原因是极简主义,而不是在本地有两个版本(GM 脚本文件和另一个文件夹中的备份),我想将代码编辑集中在一个地方,而不需要在每个文件之间复制更改,每次都是新的。

我可以看到四个选项:

1。只需从 github

安装脚本

You will need to tweak the update interval.

您需要做的就是在 github 上进入 Raw 视图,greasemonkey 会要求您安装脚本。我创建了一个 example repository to demonstrate this.

安装脚本后,进入设置,将自动更新设置为On

进一步阅读:How does user script updating work?

2。追加 <script> 标签

这是非常明显的解决方案,但出于安全原因不适合生产。您可以将脚本标签附加到文档,将您的脚本链接到 github.

3。 @require 命令

Greasemonkey 仅下载 @require 依赖项一次,因此您需要在 URL 中更改某些内容(例如 ?random_number)以在更新后强制刷新脚本。

4。 Use my refresher

我曾经制作了 Node.js 脚本,它接受文件系统上任何位置的用户脚本文件的路径。然后它将在 process.env.appdata+"\Mozilla\Firefox\Profiles\ap7ptx7o.default\gm_scripts" 中搜索这些路径(您可能需要更改此路径),并且每次您修改引用路径(GitHub 存储库中的路径)时,它都会将其复制到您的用户脚本文件夹.