[英]Transferring data between userscripts on different domains
有一种方法可以使用localStorage 在同一个域的页面之间传输数据 ,但我需要在不同的域之间传输数据。 在Chrome中,我尝试使用符号链接,以便域共享存储,但在重新启动chrome之前,在其他域中找不到在一个域中设置的项目。 如何在不同域上的用户脚本之间传输数据? 我将使用任何可行的浏览器。
这只是供个人使用
我将使用@include
包含两个域,然后使用GM_getValue
和GM_setValue
来存储和检索数据。
我还提供了一个如何使用GM_registerMenuCommand
函数的示例,该函数在用户从userscript addon弹出窗口中选择选项时打开提示。
// ==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);
}
});
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.