如何重定向到一组给定的站点中的一个? [英] How to redirect to one out of given set of sites?
问题描述
我创建了一个用户脚本来重定向到指定的多个站点之一:
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屋!