油脂猴子等待ajax

Greasemonkey wait for ajax

本文关键字:ajax 等待 猴子 油脂      更新时间:2023-09-26

我有这段代码,我想执行它应该打开任何链接与短语"/ThisWord/"在它

// ==UserScript==
// @name        Test
// @namespace   Test
// @description Test  
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant       none
// @include     http://website.com/
// ==/UserScript==
setTimeout(testLinks, 10000);
function testLinks() {
var UseThisone = $("a:contains('/profile/')");
GM_openInTab(UseThisone[0].href);
}

我只是包装整个事情与超时,但我不能得到任何链接打开

上面的代码可以工作吗?我似乎不能让它打开url,更不用说在一个新的选项卡

还有一件事,我希望它在10秒的间隔打开每个Url,这是可能的吗?

谢谢你的帮助!

// ==UserScript==
// @name        Test
// @namespace   Test
// @description Test  
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant       GM_openInTab
// @include     http://website.com/
// ==/UserScript==
setTimeout(testLinks, 10000);
function testLinks() {
    var INTERVAL = 10000;
    var delay = -INTERVAL;
    $('a[href*="/profile/"]').each(function(i, el) {
        //avoid infinite recursion, which is subject to @include rules
        if(el.href != location.href) {
            var d = (delay += INTERVAL);
            setTimeout(function() {
                GM_openInTab(el.href);
            }, d);
        }
    });
}