无事水,但要好|

Nolca

园龄:6年9个月粉丝:12关注:9

GM_registerMenuCommand()注册菜单模板,TemperMonkey油猴脚本开发

注册菜单

  1. 点击事件
  2. 注册实例
  3. 设置默认值
  4. 将handle(手握实例的变量)赋值给一个变量
function menu_Func_click() {
GM_setValue('Func', !GM_getValue('Func')); // 开关
GM_unregisterMenuCommand(menu_Func); //卸载再注册
// 强制等待下一个事件循环
setTimeout(() => {
menu_Func = menu_Func_regist();
}, 0);
};
function menu_Func_regist() {
return GM_registerMenuCommand(
`${GM_getValue('Func') ? '✅' : '❌'}`,
menu_Func_click,
{
accessKey: 'f',
autoClose: false
}
);
};
if (GM_getValue('Func') === undefined) GM_setValue('Func', true);
let menu_Func = menu_Func_regist();

别的脚本采用了全部刷新的策略,用list然后全部遍历更新

问题:脚本加载了不止1次,但我希望只运行一次

https://github.com/Tampermonkey/tampermonkey/issues/1730
https://github.com/Tampermonkey/tampermonkey/issues/1279
解决:添加@noframes

chrome系利用@require调试本地脚本

https://www.cnblogs.com/hyaray/p/7509572.html

// ==UserScript==
// @name Local Script DEBUG
// @namespace http://tampermonkey.net/
// @version 2024-10-08
// @description try to take over the world!
// @author You
// @match https://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @require file:///home/root/my_local_script.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
})();

资源

https://learn.scriptcat.org/油猴教程/中级篇/本地文件访问权限与外部开发/

本文作者:Nolca

本文链接:https://www.cnblogs.com/nolca/p/18451553

版权声明:本作品采用 收益分享revenue sharing 许可协议进行许可。

posted @   Nolca  阅读(119)  评论(0编辑  收藏  举报
历史上的今天:
2023-10-08 异步中.then()的坑爹
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 ⏩intro 山姆精
  2. 2 🎸吉他 马叉
  3. 3 ☁升调 山姆精
  4. 4 🐦Flutter Virtual Riot/Madi
  5. 5 🎶纯律 山姆精
  6. 6 👻yeah~Color Bass! VR
🎸吉他 - 马叉
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.