Javascript 篡改猴子脚本未运行jquery

Javascript 篡改猴子脚本未运行jquery,javascript,jquery,tampermonkey,Javascript,Jquery,Tampermonkey,我试图执行一个脚本与篡改猴子,它添加了一个图标,并在点击打开网页内的所有链接的任务,这里是脚本的来源 在启用脚本的页面上添加图标,但单击链接无效 我发现这可能与jquery兼容性问题有关,并尝试了以下加载jquery的更改 // ==UserScript== // @name Open CodeProject Links // @namespace http://hibbard.eu/ // @version 0.1 // @description Opens all of

我试图执行一个脚本与篡改猴子,它添加了一个图标,并在点击打开网页内的所有链接的任务,这里是脚本的来源

在启用脚本的页面上添加图标,但单击链接无效

我发现这可能与jquery兼容性问题有关,并尝试了以下加载jquery的更改

// ==UserScript==
// @name       Open CodeProject Links
// @namespace  http://hibbard.eu/
// @version    0.1
// @description  Opens all of the links from the CodeProject newsletter in one go
// @match *://www.codeproject.com/script/Mailouts/*
// @copyright  2012+, hibbard.eu
// @require https://code.jquery.com/jquery-latest.js
// @grant GM_log
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
    script.addEventListener('load', function() {
        var script = document.createElement("script");
        script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}
function main(){
$(document).ready(function() {
  //var my_jquery = jQuery;
  //jQuery.noConflict(true);
  //var $ = my_jquery, jQuery = my_jquery;
  var hrefs = new Array();
  var elements = $('.headline > a');
  elements.each(function() {
    hrefs.push($(this).attr('href'));
  });

  $('body').append('<input type="button" value="Open Links" id="CP">');
  $("#CP").css("position", "fixed").css("top", 0).css("left", 0);
  $('#CP').click(function(){
    $.each(hrefs, function(index, value) {
      setTimeout(function(){
       window.open(value, '_blank');
      },1000);
    });
  });
});
}
// load jQuery and execute the main function
addJQuery(main);
/==UserScript==
//@name打开代码项目链接
//@名称空间http://hibbard.eu/
//@version 0.1
//@description一次性打开CodeProject新闻稿中的所有链接
//@match*://www.codeproject.com/script/Mailouts/*
//@版权所有2012+,hibbard.eu
//@需要https://code.jquery.com/jquery-latest.js
//@grant GM_log
//==/UserScript==
//-需要@grant指令来恢复适当的沙箱。
//加载jQuery并在jQuery完成加载时调用回调函数的函数
函数addJQuery(回调){
var script=document.createElement(“脚本”);
script.setAttribute(“src”,“//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js”);
script.addEventListener('load',function()){
var script=document.createElement(“脚本”);
script.textContent=“window.jQ=jQuery.noConflict(true);(“+callback.toString()+”);”;
document.body.appendChild(脚本);
},假);
document.body.appendChild(脚本);
}
函数main(){
$(文档).ready(函数(){
//var my_jquery=jquery;
//jQuery.noConflict(true);
//var$=my\u jquery,jquery=my\u jquery;
var hrefs=新数组();
变量元素=$('.headline>a');
元素。每个(函数(){
hrefs.push($(this.attr('href'));
});
$('body')。追加('');
$(“#CP”).css(“位置”,“固定”).css(“顶部”,0).css(“左侧”,0);
$('#CP')。单击(函数(){
$.each(hrefs,函数(索引,值){
setTimeout(函数(){
打开(值为“U空白”);
},1000);
});
});
});
}
//加载jQuery并执行main函数
addJQuery(main);

但这也不起作用。有人能帮我解决使用tamper monkey执行按钮点击的问题吗?

这是因为没有为输入元素的css定义z-index元素,因为div使输入按钮过度扭曲,使其不可点击

下面是工作代码

$(document).ready(function() {
var hrefs = new Array();
var elements = $('.headline > a');
elements.each(function() {
hrefs.push($(this).attr('href'));
});
$('body').append('<input type="button" value="Open Links" id="CP">');
$("#CP").css("position", "fixed").css("top", 0).css("left", 0).css("z-index", 1000);
$('#CP').click(function(){
$.each(hrefs, function(index, value) {
setTimeout(function(){
window.open(value, '_blank');
},1000);
});
});
});
$(文档).ready(函数(){
var hrefs=新数组();
变量元素=$('.headline>a');
元素。每个(函数(){
hrefs.push($(this.attr('href'));
});
$('body')。追加('');
$(“#CP”).css(“位置”,“固定”).css(“顶部”,0).css(“左侧”,0).css(“z-index”,1000);
$('#CP')。单击(函数(){
$.each(hrefs,函数(索引,值){
setTimeout(函数(){
打开(值为“U空白”);
},1000);
});
});
});

这是因为没有为输入元素的css定义z-index元素,因为div使输入按钮过度扭曲,使其不可点击

下面是工作代码

$(document).ready(function() {
var hrefs = new Array();
var elements = $('.headline > a');
elements.each(function() {
hrefs.push($(this).attr('href'));
});
$('body').append('<input type="button" value="Open Links" id="CP">');
$("#CP").css("position", "fixed").css("top", 0).css("left", 0).css("z-index", 1000);
$('#CP').click(function(){
$.each(hrefs, function(index, value) {
setTimeout(function(){
window.open(value, '_blank');
},1000);
});
});
});
$(文档).ready(函数(){
var hrefs=新数组();
变量元素=$('.headline>a');
元素。每个(函数(){
hrefs.push($(this.attr('href'));
});
$('body')。追加('');
$(“#CP”).css(“位置”,“固定”).css(“顶部”,0).css(“左侧”,0).css(“z-index”,1000);
$('#CP')。单击(函数(){
$.each(hrefs,函数(索引,值){
setTimeout(函数(){
打开(值为“U空白”);
},1000);
});
});
});