Greasemonkey wait for ajax

放肆的年华 提交于 2020-01-07 09:25:24

问题


I have this code I want to execute it should open any links with the phrase "/ThisWord/" in it

// ==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);

}

I just wrappedd the whole thing with a timeout, but i cant get any links to open

Does the above code even work? I can't seem to get it to open the urls let alone in a new tab

One more thing, I would want it to open each Url in 10 second intervals, is that possible?

Thanks for the help!


回答1:


// ==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);
        }
    });
}


来源:https://stackoverflow.com/questions/22712942/greasemonkey-wait-for-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!