Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

javascript - Greasemonkey wait for ajax

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
// ==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);
        }
    });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...