问题
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