[英]Transferring data between userscripts on different domains
There's a way to transfer data between pages on the same domain , using localStorage, but I need to transfer data between different domains. 有一种方法可以使用localStorage 在同一个域的页面之间传输数据 ,但我需要在不同的域之间传输数据。 In Chrome, I tried using symbolic links so the domains share the storage, but items set in one domain aren't found at the other domain until I reboot chrome.
在Chrome中,我尝试使用符号链接,以便域共享存储,但在重新启动chrome之前,在其他域中找不到在一个域中设置的项目。 How do I transfer data between userscripts on different domains?
如何在不同域上的用户脚本之间传输数据? I'll use any browser that'll work.
我将使用任何可行的浏览器。
This'll only be for personal use 这只是供个人使用
I would include both domains using @include
and then use GM_getValue
and GM_setValue
to store and retrieve the data. 我将使用
@include
包含两个域,然后使用GM_getValue
和GM_setValue
来存储和检索数据。
I've also included an example on how to use the GM_registerMenuCommand
function which opens a prompt when the user selects the option from the userscript addon popup. 我还提供了一个如何使用
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.