Tampermonkey GM_xmlhttpRequest无法正常工作

时间:2015-06-19 19:46:55

标签: javascript tampermonkey

现在,我将向您展示我的剧本,今天不能正常工作(三个月前工作,今天不能工作)

// ==UserScript==
// @name         My Fancy New Userscript
// @namespace    http://*/*
// @version      0.1
// @description  enter something useful
// @author       You
// @match        https://www.facebook.com/
// @grant        GM_xmlhttpRequest
// ==/UserScript==
var x=document.createElement('BUTTON');
x.style.width="30px";
x.style.height="30px";
x.style.position="fixed";
x.style.top="5px";
x.style.left="1250px";
x.style.zIndex="388";
x.style.backgroundRepeat="no-repeat";
x.style.backgroundSize="30px 30px";
x.style.backgroundImage="url(http://www.iconarchive.com/download/i76816/wineass/ios7-redesign/Weather.ico)";
console.log("start");
x.onclick=function(){
GM_xmlhttpRequest({
  method: "GET",
  url: "http://www.3bmeteo.com/meteo/cosenza",
  onload: function(response) {
      pars=new DOMParser();
      var t=pars.parseFromString(response.responseText,"text/html");
      var y=t.getElementsByClassName('col-xs-2-4');
      var z=t.getElementsByClassName('col-xs-1-4 big');
      var text="";
      text+=y[0].innerText+" "+z[0].innerText+"\n"+y[1].innerText+"     "+z[1].innerText+"\n"+y[2].innerText+" "+z[2].innerText+"\n"+y[3].innerText+" "+z[3].innerText+"\n"+y[4].innerText+" "+z[4].innerText+"\n";
  alert(text);
  console.log("finished")}
});
};
document.body.appendChild(x);

var x1=document.createElement('BUTTON');
x1.style.width="30px";
x1.style.height="30px";
x1.style.position="fixed";
x1.style.top="5px";
x1.style.left="1290px";
x1.style.zIndex="388";
x1.style.backgroundRepeat="no-repeat";
x1.style.backgroundSize="30px 30px";
    x1.style.backgroundImage="url(http://www.iconarchive.com/download/i76816/wineass/ios7-redesign/Weather.ico)";
x1.onclick=function(){
GM_xmlhttpRequest({
  method: "GET",
  url: "http://www.3bmeteo.com/meteo/cosenza/1",
  onload: function(response) {
  pars=new DOMParser();
  var t=pars.parseFromString(response.responseText,"text/html");
  var y=t.getElementsByClassName('big switchcelsius switch-te active');
  var z=t.getElementsByClassName('hidden-xs');
  var text="";
  text+="DOMANI:"+y[0].innerText+" "+z[8].innerText+"\n"+y[1].innerText+" "+z[9].innerText+"\n"+y[2].innerText+" "+z[10].innerText+"\n"+y[3].innerText+" "+z[11].innerText;
  alert(text);}
});
};
document.body.appendChild(x1);

问题是什么?为什么不运行此脚本? 我想制作一个警告框,显示一些meteo数据。 我试着记录请求的状态,但是控制台记录我只是启动,也许请求不是make。 也许我站在错误的地方。我不尊重CORS规则,为此它不起作用。但我可以解释一下,如果我不改变,为什么这个脚本在此错误之前完美运行什么?

0 个答案:

没有答案