2

我创建了一个用户脚本来重定向到指定的多个站点中的一个:

// ==UserScript==
// @id             fvhfy464
// @name           [udit]redirector to yahoo or google
// @version        1.0
// @namespace      
// @author         
// @description    
// @include        http://yahoo.com
// @include        http://google.com
// @include        http://bing.com
// @run-at         document-end
// ==/UserScript==

setTimeout(function() {
    window.location.href("http://yahoo.com","http://google.com","http://bing.com")
}, 4000);

但它不起作用。

(来自评论:)
我想以随机方式在一个选项卡中打开多个站点,一个接一个,时间间隔为 4 秒。它就像网站的屏幕保护程序。

它可以永远消失。要停止,我只需要关闭选项卡。而且,我只会将那些网站设置在@include我希望这个脚本在其中工作的那些网站上。它就像照片等的屏幕保护程序。

4

1 回答 1

2

将要显示的站点列表放入数组中。然后您可以关闭当前页面并按顺序转到下一个页面,或者选择一个随机的下一个页面。

例如,这是一个有序的幻灯片:

// ==UserScript==
// @name        Multipage, MultiSite slideshow of sorts
// @match       http://*.breaktaker.com/*
// @match       http://*.imageshack.us/*
// @match       http://static.tumblr.com/*
// @match       http://withfriendship.com/images/*
// ==/UserScript==

var urlsToLoad  = [
    'http://www.breaktaker.com/albums/pictures/animals/BigCat.jpg'
    , 'http://img375.imageshack.us/img375/8105/bigcats34ye4.jpg'
    , 'http://withfriendship.com/images/g/33769/1.jpg'
    , 'http://static.tumblr.com/yd0wcto/LXQlx109d/bigcats.jpg'
];

setTimeout (GotoNextURL, 4000);

function GotoNextURL () {
    var numUrls     = urlsToLoad.length;
    var urlIdx      = urlsToLoad.indexOf (location.href);
    urlIdx++;
    if (urlIdx >= numUrls)
        urlIdx = 0;

    location.href   = urlsToLoad[urlIdx];
}


以下是随机提供的相同网站:

// ==UserScript==
// @name        Multipage, MultiSite slideshow of sorts
// @match       http://*.breaktaker.com/*
// @match       http://*.imageshack.us/*
// @match       http://static.tumblr.com/*
// @match       http://withfriendship.com/images/*
// ==/UserScript==

var urlsToLoad  = [
    'http://www.breaktaker.com/albums/pictures/animals/BigCat.jpg'
    , 'http://img375.imageshack.us/img375/8105/bigcats34ye4.jpg'
    , 'http://withfriendship.com/images/g/33769/1.jpg'
    , 'http://static.tumblr.com/yd0wcto/LXQlx109d/bigcats.jpg'
];

setTimeout (GotoRandomURL, 4000);

function GotoRandomURL () {
    var numUrls     = urlsToLoad.length;
    var urlIdx      = urlsToLoad.indexOf (location.href);
    if (urlIdx >= 0) {
        urlsToLoad.splice (urlIdx, 1);
        numUrls--;
    }

    urlIdx          = Math.floor (Math.random () * numUrls);
    location.href   = urlsToLoad[urlIdx];
}
于 2012-07-06T16:06:36.740 回答