gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:24:37 26 4
gpt4 key购买 nike

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

这将仅供个人使用

最佳答案

我会使用 @include 包括这两个域然后使用 GM_getValueGM_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);
}
});

})();

关于javascript - 在不同域的用户脚本之间传输数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40569901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com