gpt4 book ai didi

javascript - 如何使页面真正重新加载

转载 作者:行者123 更新时间:2023-11-30 18:20:01 25 4
gpt4 key购买 nike

我有一个 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];
}

当我要顺序加载同一网站的 2 个页面时,问题就来了:脚本停止工作,因为该网站使用 AJAX 以便更快地加载其页面。

如何强制此脚本完全重新加载页面?

如你所见,他已经尝试过:

//--- Catch new pages loaded by WELL BEHAVED ajax. 
window.addEventListener ("hashchange", FireTimer, false);

解决了这个问题,但是没有达到预期的效果。

特别是给我这个问题的网站是 ink361.com。我已经创建了一个 jsFiddle 的例子,他的来源:http://jsfiddle.net/XjjfK/

提前致谢。

最佳答案

我无法登录,但脚本非常适合我。
我完全按照下面的方式安装了脚本,它在这 3 个 ink361.com 页面之间循环,正如预期的那样。

一些你要做/检查的事情:

  1. 你在使用 your other script (或任何其他 GM 脚本)在同一页面上?

  2. 当您浏览 ink361.com 时,Greasemonkey 菜单显示什么? GM menu
    GM menu results

  3. 听起来安装的脚本没有 hashchange 代码 -- 该代码应该可以在该站点上运行,因为它确实更新了主题标签。

    1. 卸载脚本。
    2. 重新启动 Firefox。
    3. 重新安装脚本。

  4. pastebin.com 上发布您正在使用的未经编辑的准确脚本,并在此处链接到它。

  5. 卸载 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]);
}

关于javascript - 如何使页面真正重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com