Tampermonkey 脚本不是 运行 jquery

Tamper monkey script not running jquery

我正在尝试使用 tamper monkey 执行一个脚本,它添加了一个图标并完成了在点击时打开网页中所有 link 的任务,这里是脚本的源代码 https://gist.github.com/jameshibbard/3831983#file-gistfile1-js

在启用脚本的页面上添加了图标,但单击 link 不起作用。

我发现它可能与 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);

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

这是因为 z-index 元素没有为 input 元素的 css 定义,因此输入按钮被 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);
});
});
});