在不同域的用户脚本之间传输数据

Transferring data between userscripts on different domains

有一种方法 transfer data between pages on the same domain,使用 localStorage,但我需要在不同域之间传输数据。在 Chrome 中,我尝试使用符号链接以便域共享存储空间,但是在我重新启动 chrome 之前,在一个域中设置的项目在另一个域中找不到。如何在不同域的用户脚本之间传输数据?我会使用任何可用的浏览器。

这将仅供个人使用

我会使用 @include and then use GM_getValue and GM_setValue 来包括两个域来存储和检索数据。

我还提供了一个示例,说明如何使用 GM_registerMenuCommand 函数,该函数会在用户从用户脚本插件弹出窗口中选择选项时打开提示。

// ==UserScript==
// @name         Pinky
// @namespace    http://pinkyAndTheBrain.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      https://domain1.com
// @include      https://domain2.com
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// ==/UserScript==
/* global GM_getValue, GM_setValue, GM_registerMenuCommand */
/* jshint esnext:true */
(() => {
  'use strict';

  // get previous setting (or set to Pinky as default)
  let char = GM_getValue('character', 'Pinky');

  // do something fun!

  // called through the userscript addon
  GM_registerMenuCommand('Are you Pinky or Brain?', () => {
    const value = prompt('Enter "p" or "b"', char);
    if (value !== null) {
      // default to Pinky
      char = /^b/i.test(value) ? 'Brain' : 'Pinky';
      GM_setValue('character', char);
    }
  });

})();