相关疑难解决方法(0)

如何在Google Chrome中的Greasemonkey脚本中使用jQuery?

正如你们中的一些人可能知道的那样,谷歌Chrome对Greasemonkey脚本有一些严重的限制.

铬不支持@require,@resource,unsafeWindow,GM_registerMenuCommand,GM_setValue,或GM_getValue.

没有require,我找不到在Google Chrome下的Greasemonkey脚本中包含jQuery库的方法.

有人在这件事上有一些建议吗?

jquery greasemonkey google-chrome require userscripts

155
推荐指数
6
解决办法
6万
查看次数

如何在注入代码中使用GM_xmlhttpRequest?

我正在编写一个注入网页的用户脚本.该脚本从Web服务器读取一些数据,我想将消息发送到侦听应用程序以对数据做出反应.

现在,我正在做的就是尝试将一个字符串命令发送到我的监听应用程序,看看我是否可以读取它.我的代码在注入之前工作,但之后我得到一个"未定义的引用错误".

我怀疑这与"Greasemonkey访问违规"有关.但是,我一直无法找到有效的解决方案.我正在开发Chrome.

这是我无法工作的代码部分.

GM_xmlhttpRequest({
   method: "POST", 
   url: "http://localhost:7777", 
   data: "testing123",
   headers:  {
         "Content-Type": "application/x-www-form-urlencoded"
             },
   onload: function(response) 
   {
      if (response.responseText.indexOf("TEST") > -1) 
      {
         console.log("Response confirmed..."); 
      }
   }
}); 
Run Code Online (Sandbox Code Playgroud)

我对脚本很新,所以也许我错过了一些明显的东西.如何在注入的代码中使用它?

javascript greasemonkey userscripts google-chrome-extension

8
推荐指数
1
解决办法
8952
查看次数

如何从必须在目标页面范围内运行的代码调用Greasemonkey的GM_函数?

我问了一个问题并在这里得到了答案:如何从Greasemonkey调用此YouTube功能?

该代码可以工作并向页面添加一个按钮,用于捕获视频时间.
但是,关键部分必须在目标页面范围内运行 - 其中Greasemonkey的GM_功能不可用.

我想用来GM_setValue()录制视频时间.如何GM_setValue()从我的按钮click处理程序中调用?

以下是完整脚本的相关部分(右键单击以保存):

... ...

//-- Only run in the top page, not the various iframes.
if (window.top === window.self) {
    var timeBtn         = document.createElement ('a');
    timeBtn.id          = "gmTimeBtn";
    timeBtn.textContent = "Time";
    //-- Button is styled using CSS, in GM_addStyle, below.

    document.body.appendChild (timeBtn);

    addJS_Node (null, null, activateTimeButton);
}

function activateTimeButton () {
    var timeBtn = document.getElementById ("gmTimeBtn");
    if (timeBtn) {
        timeBtn.addEventListener ('click',
            function …
Run Code Online (Sandbox Code Playgroud)

javascript youtube greasemonkey youtube-api

5
推荐指数
1
解决办法
3498
查看次数

GM_getValue未定义错误

在我的greasemonkey脚本中,我想检查GM值:用户名和密码是否设置,但是当我尝试以下代码时它会给我回错:

TypeError: GM_getValue(...) is undefined    
...f (GM_getValue ("username").length == 0 + GM_getValue ("password").length == 0 )
Run Code Online (Sandbox Code Playgroud)

码:

if (GM_getValue ("username").length == 0 + GM_getValue ("password").length == 0 ){
var username = $('input[name=username]');
var password = $('input[name=password]');

//Username en Password in Firefox zetten met GM_setValue
$(".button").click(function(){

GM_setValue ("username", username.val() );
GM_setValue ("password", password.val() );

});
}
Run Code Online (Sandbox Code Playgroud)

greasemonkey

0
推荐指数
1
解决办法
4066
查看次数