如何重定向到给定站点集中的一个? [英] How to redirect to one out of given set of sites?

查看:62
本文介绍了如何重定向到给定站点集中的一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a userscript to redirect to one out of the specified multiple sites:

// ==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秒的时间间隔随机地在一个选项卡中一个接一个地打开多个站点.就像网站的屏幕保护程序.

(From comments:)
I want to open multiple sites in a single tab, one after another, in a random way with a time interval of 4 seconds. It's like a screensaver of sites.

它可以永远消失.要停止,我只需要关闭选项卡.而且,我将只在我希望此脚本运行的 @include 中设置这些站点.就像是照片的屏幕保护程序.

It can go forever. To stop, I just have to close the tab. And, I'll only set those sites in the @include which I want this script to work on. It's like a screensaver of photos etc.

推荐答案

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

Put the list of sites, you want to display, into an array. Then you can key off the current page and either go to the next one in order, or pick a random next one.

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

For example, here is an ordered slide-show:

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



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



Here's the same sites served up randomly:

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

这篇关于如何重定向到给定站点集中的一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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