Tampermonkey - 右键菜单 [英] Tampermonkey - Right click menu
问题描述
使用Tampermonkey可以在Chrome中创建右键菜单选项吗?
我找到 GM_registerMenuCommand
但它似乎没有在右键菜单中显示任何新项目。
另一个问题是我使用 GM_openInTab
在测试脚本中,但由于某种原因它似乎无限循环。它应该只在单击菜单后触发,为什么会发生这种情况?
另外我想知道是否有一种方法可以通过自定义右键单击以更高级的方式执行此操作图标等?
Firefox有一个适用于菜单的GM脚本,但在Chrome中似乎没有任何显示,所以有一种方法可以让它工作。
// == UserScript ==
// @name上下文菜单
// @namespace http:// tampermonkey.net/
// @description测试
// @version 0.1
// @ author author
// @include *
// @exclude文件: // *
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// == / UserScript ==]
(function() {
'使用严格';
功能测试(){
GM_openInTab(https://website.net);
}
GM_registerMenuCommand(hello,test(),h);
})();
根据
With Tampermonkey is there any way to create a right click menu option in Chrome?
I found GM_registerMenuCommand
but it does not seem to show any new items in the right click menu.
Another problem is I use GM_openInTab
in the test script but it seems to loop infinitely for some reason. It should only trigger after the menu is clicked, why would this happen?
Also I am wondering is there a way to do this in a more advanced way with custom right click icons etc?
There was a GM script for Firefox that worked for menus but in Chrome nothing seems to show so it would be good to have a way to have this working.
// ==UserScript==
// @name Context Menu
// @namespace http://tampermonkey.net/
// @description Test
// @version 0.1
// @author author
// @include *
// @exclude file://*
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// ==/UserScript==]
(function() {
'use strict';
function test() {
GM_openInTab("https://website.net");
}
GM_registerMenuCommand("hello", test(), "h");
})();
As per wOxxOm comment, it is possible using @run-at context-menu
.
Example:
// ==UserScript==
// @name Go to Website.Net
// @namespace http://tampermonkey.net/
// @description Context menu to execute UserScript
// @version 0.1
// @author author
// @include *
// @grant GM_openInTab
// @run-at context-menu
// ==/UserScript==]
(function() {
'use strict';
GM_openInTab("https://website.net");
})();
Result: (works nicely :)
这篇关于Tampermonkey - 右键菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!