value问题处理
Some checks failed
test / Run tests (push) Failing after 3s
build / Build (push) Failing after 6s

This commit is contained in:
2025-04-09 18:05:59 +08:00
parent 9f70b7eb7a
commit 0d86dae710
18 changed files with 122 additions and 68 deletions

View File

@@ -9,7 +9,7 @@
// @connect example.com
// ==/UserScript==
// GM_cookie("store") 方法请看gm_value.js的例子, 可用于隐身窗口的操作
// GM_cookie("store") 方法请看storage_name/gm_value.js的例子, 可用于隐身窗口的操作
GM_cookie("set", {
url: "http://example.com/cookie",

View File

@@ -11,13 +11,10 @@
// @grant GM_addValueChangeListener
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_cookie
// ==/UserScript==
GM_addValueChangeListener("test_set", function (name, oldval, newval, remote, tabid) {
GM_cookie("store", tabid, (storeId) => {
console.log("store", storeId);
});
console.log("test_set change", name, oldval, newval, remote, tabid);
});
setInterval(() => {

View File

@@ -0,0 +1,18 @@
// ==UserScript==
// @name gm value storage 设置方
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description 多个脚本之间共享数据 设置方
// @author You
// @match https://bbs.tampermonkey.net.cn/
// @run-at document-start
// @grant GM_setValue
// @grant GM_deleteValue
// @storageName example
// ==/UserScript==
setTimeout(() => {
GM_deleteValue("test_set");
}, 3000);
GM_setValue("test_set", new Date().getTime());

View File

@@ -0,0 +1,28 @@
// ==UserScript==
// @name gm value storage 读取与监听方
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description 多个脚本之间共享数据 读取与监听方
// @author You
// @match https://bbs.tampermonkey.net.cn/
// @run-at document-start
// @grant GM_getValue
// @grant GM_addValueChangeListener
// @grant GM_listValues
// @grant GM_cookie
// @storageName example
// ==/UserScript==
GM_addValueChangeListener("test_set", function (name, oldval, newval, remote, tabid) {
console.log("test_set change", name, oldval, newval, remote, tabid);
// 可以通过tabid获取到触发变化的tab
// GM_cookie.store可以获取到对应的cookie storeId
GM_cookie("store", tabid, (storeId) => {
console.log("store", storeId);
});
});
setInterval(() => {
console.log(GM_getValue("test_set"));
console.log(GM_listValues());
}, 2000);