我有一个Greasemonkey脚本(由另一个编码器 - Brock Adams编写),它在代码开头按顺序加载数组中包含的页面。 How to open a list of pages automatically and sequentially?
// ==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];
}
当我有两个相同网站的页面按顺序加载时,问题出现了:脚本停止工作,因为网站使用AJAX以便更快地加载其页面。
如何强制此脚本完全重新加载页面?
你可以看到他已经尝试过:
//--- Catch new pages loaded by WELL BEHAVED ajax.
window.addEventListener ("hashchange", FireTimer, false);
解决此问题,但无法按预期工作。
特别是给我这个问题的网站是ink361.com。 我创建了一个jsFiddle作为他的来源的一个例子:http://jsfiddle.net/XjjfK/
提前致谢。
答案 0 :(得分:2)
我无法登录,但脚本对我来说非常合适 我完全按照下面的方式安装了脚本,它在这3个ink361.com页面之间循环,正如预期的那样。
有些事要做/检查:
您是否在同一页面上使用your other script(或任何其他GM脚本)?
当您浏览ink361.com时,Greasemonkey菜单会显示什么?
听起来安装的脚本没有hashchange
代码 - 它应该在该网站上运行,因为它 更新主题标签。
在pastebin.com发布您正在使用的确切未经编辑的脚本,并在此处链接到该文字。
卸载ink361.com的任何其他脚本,并仅安装以下脚本
它有用吗?
如果没有,请在pastebin.com发布控制台日志或Firebug的日志。
// ==UserScript==
// @name _del me
// @namespace _pc
// @include http://ink361.com/*
// @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.
*/
console.log ("Start: ", Date ());
var urlsToLoad = [
'http://ink361.com/#/users/206053596/photos'
, 'http://ink361.com/#/users/199101377/photos'
, 'http://ink361.com/#/users/203767882/photos'
];
/*--- 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 (zParam) {
console.log ("Fire: ", zParam);
console.log (Date ());
setTimeout (GotoNextURL, 5000); // 5000 == 5 seconds
}
function GotoNextURL () {
var numUrls = urlsToLoad.length;
var urlIdx = urlsToLoad.indexOf (location.href);
urlIdx++;
if (urlIdx >= numUrls)
urlIdx = 0;
console.log ("Loading: ", urlsToLoad[urlIdx]);
location.assign (urlsToLoad[urlIdx]);
}