我有一个 Greasemonkey 脚本(由另一个编码员 - Brock Adams 编写),它在代码开头按顺序加载包含在数组中的页面。 如何自动按顺序打开页面列表?
// ==UserScript==
// @name Multipage, MultiSite slideshow of sorts
// @include http://google.com/*
// @include http://site2/*
// @include http://site3/*
// @include http://site4/*
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design
change introduced in GM 1.0.
It restores the sandbox.
*/
var urlsToLoad = [
'http://google.com/'
, 'http://site2/somepage/'
, 'http://site3/somepage/'
, 'http://site4/somepage/'
];
/*--- Since many of these sites load large pictures, Chrome's and
Firefox's injection may fire a good deal before the image(s)
finish loading.
So, insure script fires after load:
*/
window.addEventListener ("load", FireTimer, false);
if (document.readyState == "complete") {
FireTimer ();
}
//--- Catch new pages loaded by WELL BEHAVED ajax.
window.addEventListener ("hashchange", FireTimer, false);
function FireTimer () {
setTimeout (GotoNextURL, 5000); // 5000 == 5 seconds
}
function GotoNextURL () {
var numUrls = urlsToLoad.length;
var urlIdx = urlsToLoad.indexOf (location.href);
urlIdx++;
if (urlIdx >= numUrls)
urlIdx = 0;
location.href = urlsToLoad[urlIdx];
}
当我要按顺序加载同一网站的 2 个页面时,问题就出现了:脚本停止工作,因为该网站使用 AJAX 以便更快地加载其页面。
如何强制此脚本完全重新加载页面?
如您所见,他已经尝试过:
//--- Catch new pages loaded by WELL BEHAVED ajax.
window.addEventListener ("hashchange", FireTimer, false);
来解决这个问题,但它没有按预期工作。
特别是给我这个问题的网站是ink361.com。我创建了一个他的来源示例的 jsFiddle:http: //jsfiddle.net/XjjfK/
提前致谢。