Javascript 动态创建greasemonkey脚本
我正在尝试创建一个动态的GM脚本。这是我认为可以做到的Javascript 动态创建greasemonkey脚本,javascript,dynamic,greasemonkey,window.open,Javascript,Dynamic,Greasemonkey,Window.open,我正在尝试创建一个动态的GM脚本。这是我认为可以做到的 win = window.open('myScript.user.js'); win.document.writeln('// ==UserScript=='); win.document.writeln('// @name sample script'); win.document.writeln('// @description alerts hi'); win.document.writeln('// @incl
win = window.open('myScript.user.js');
win.document.writeln('// ==UserScript==');
win.document.writeln('// @name sample script');
win.document.writeln('// @description alerts hi');
win.document.writeln('// @include http://www.google.com/*');
win.document.writeln('// ==/UserScript==');
win.document.writeln('');
win.document.writeln('(function(){alert("hi");})()');
win.document.close();
但事实并非如此。有人知道如何做吗?您不能单独使用Greasemonkey动态创建Greasemonkey脚本 GM脚本不是HTML页面的一部分,因此将GM代码写入页面将永远无法工作。脚本需要安装到GM的脚本管理系统中 GM脚本无法写入文件系统,也无法访问足够的浏览器chrome来安装脚本加载项
- 您可以编写一个GM脚本,将其他脚本发布到服务器,然后将浏览器发送到该服务器。然后,GM将提示用户安装新脚本
- 您可能可以编写一个可以编写GM脚本的浏览器附加组件,但我怀疑这种方法会很困难
- 您可能可以编写一个Python(或C、VB等)程序,生成用于安装的GM脚本。通过额外的工作,这样的程序也可能自动安装脚本
无论如何,为什么要动态创建Greasemonkey脚本?可能有一种更简单的方法来实现真正的目标
OP评论/澄清更新:
Re:
“我希望用户能够选择要阻止的元素,然后创建一个脚本,在该域的所有站点上将该元素的显示设置为无”
一种方法是:
请注意,根据元素的不同,优秀者可能能够更优雅地阻止元素(也节省带宽/DL时间).window.open不适用于.js文件,而是使用html并用标记包装代码。它包装在onclick事件中,因此它打开窗口的方式与我希望的不同。我希望用户能够选择要阻止的元素,然后创建一个脚本,将该元素在该域的所有站点上的显示设置为“无”。我已更新了我的回答提纲这样做的方法,不需要动态脚本。