本帖最后由 cyfung1031 于 2025-11-25 00:36 编辑
原文: https://github.com/scriptscat/scriptcat/issues/891
脚本猫:https://scriptcat.org/zh-CN/script-show-page/4709
测试:
https://detail.zol.com.cn/notebook/index1173171.shtml
https://detail.zol.com.cn/notebook/index1211055.shtml
https://detail.zol.com.cn/notebook/index1207474.shtml
https://detail.zol.com.cn/notebook/index1322065.shtml
https://detail.zol.com.cn/notebook/index1143937.shtml
https://detail.zol.com.cn/notebook/index1212920.shtml
https://detail.zol.com.cn/notebook/index1165564.shtml
https://detail.zol.com.cn/notebook/index1210802.shtml
// ==UserScript==
// @name Example Script for GM_lock
// @namespace yourname.scripts
// @version 0.1
// @description 把当前网页URL保存到存储列表中
// @author You
// @match *://*/*
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.setValues
// @grant GM.deleteValue
// @grant GM.deleteValues
// @grant GM.listValues
// @grant GM_addValueChangeListener
// @grant GM_removeValueChangeListener
// @require https://scriptcat.org/lib/4709/0.1.0/GM_lock.js?sha384-dbz4ENOCrR50Xa7gxF6jsZLb8ExaYEMuOpTpDgw6Xt4yavf5ZgoPnbaoN4M3MIMQ
// @noframes
// ==/UserScript==
/* global GM_lock */
(function () {
'use strict';
GM_lock("lock_urls", async () => {
console.log("开始", Date.now(), performance.now());
// 等一下这个页面SC的缓存更新
await new Promise(resolve => setTimeout(resolve, 50));
// 从存储中读取已有的列表
let list = await GM.getValue('list', []); // 设置默认值为空数组
// 如果当前URL不在列表中,就添加进去
console.log("初始列表:", list.slice());
if (!list.includes(location.href)) {
list.push(location.href);
await GM.setValue('list', list);
console.log('✅ 已保存此页面到列表:', location.href);
} else {
console.log('ℹ️ 当前页面已在列表中');
}
// 可选:在控制台查看当前列表
console.log('当前列表:', list.slice());
// 等一下其他页面SC的缓存更新
await new Promise(resolve => setTimeout(resolve, 50));
console.log("结束", Date.now(), performance.now());
});
})();