有人遇到Greasemonkey @includes问题时无法解雇吗?

时间:2019-02-19 22:23:53

标签: firefox firefox-addon greasemonkey-4

我编写Greasemonkey脚本来完成我的工作所需的各种自动化和屏幕抓取。我有一个要处理的项目/帐户的列表,并反复遍历它们从各种Web工具中提取数据。

我捕获了文档就绪事件并从此处开始处理,完成后,我将使用window.href或仅单击指向下一页的链接按顺序加载下一页。

每当页面加载时,Greasemonkey都不会运行。控制台中没有错误,如果我只是刷新页面,它将起作用。就像@include指令失败了。我会说URL发生了变化,但是没有变化,页面刷新可以很好地启动脚本(尽管我必须停止正在执行的操作并按F5键)。

有人看过吗?我有什么可以做的(短短切换到硒)?

// ==UserScript==
// @name     testG
// @version  1
// @grant    none
// @require  https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==

var mySearches = localStorage.getItem('mySearches');
var myResults = localStorage.getItem('myResults');

if (mySearches){ 
     mySearches = JSON.parse(mySearches);


}else{
    mySearches = ["one", "two", "three","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39"];
  localStorage.setItem('mySearches', JSON.stringify(mySearches));
}

if (myResults){
   myResults = JSON.parse(myResults);   
}else{
   myResults = [];
}

$(document).ready( function() {

  var search = $("input[title='Search']");

  console.log("mySearches is " + JSON.stringify(mySearches));

  var mySearch = mySearches.shift();
    myResults.push(mySearch);
    localStorage.setItem('myResults', JSON.stringify(myResults));

  search.val( mySearch );

  if ( mySearches.length < 1){      
        localStorage.removeItem('mySearches');
    alert (myResults);
    }else{

        myResults.push(mySearch);
        localStorage.setItem('mySearches', JSON.stringify(mySearches));

        window.location.replace("https://www.google.com");
    }

} );//END DOCUMENT READY

0 个答案:

没有答案