Greasemonkey等待ajax [英] Greasemonkey wait for ajax
本文介绍了Greasemonkey等待ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有要执行的代码,应打开其中带有短语"/ThisWord/"的所有链接
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
还有一件事,我希望它以10秒的间隔打开每个网址,这可能吗?
One more thing, I would want it to open each Url in 10 second intervals, is that possible?
感谢您的帮助!
推荐答案
// ==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);
}
});
}
这篇关于Greasemonkey等待ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文