如何自动按顺序打开页面列表? [英] How do I open a list of pages automatically and sequentially?

查看:28
本文介绍了如何自动按顺序打开页面列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 Greasemonkey 按顺序加载网页列表.

I wish to load a list of webpages sequentially, with Greasemonkey.

var list = array ('http://www.google.com', 'site2', 'site3', 'site4');
window.location.href = list[0];

脚本应该如下工作:打开站点 1,等待 5 秒,打开站点 2,等待 5 秒,等等.

The script should work as follows: open site 1, wait 5 seconds, open site 2, wait 5 seconds, etc.

我不知道如何让脚本按顺序打开站点,也许将实际 URL 与列表进行比较,然后移动下一个(?).

I don't know how to make the script open sites in sequence, maybe compare the actual URL to the list and move on the next one(?).

推荐答案

这种方法,适用于 Chrome,同样适用在 Greasemonkey 中.

This approach, for Chrome, will also work in Greasemonkey.

将您的网站放在一个数组中,就像这样,但您还必须设置您的@包含@exclude@match 指令以在适当的网站上触发.

Put your sites in an array, like that, but you must also set your @include, @exclude, and @match directives to fire on the appropriate sites.

综合起来,这是一个完整的脚本:

// ==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];
}

这篇关于如何自动按顺序打开页面列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆