如何重定向到给定站点集中的一个?

编程入门 行业动态 更新时间:2024-10-23 04:56:11
本文介绍了如何重定向到给定站点集中的一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 yahoo // @include google // @include bing // @run-at document-end // ==/UserScript== setTimeout(function() { window.location.href("yahoo","google","bing") }, 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 *.breaktaker/* // @match *.imageshack.us/* // @match static.tumblr/* // @match withfriendship/images/* // ==/UserScript== var urlsToLoad = [ 'www.breaktaker/albums/pictures/animals/BigCat.jpg' , 'img375.imageshack.us/img375/8105/bigcats34ye4.jpg' , 'withfriendship/images/g/33769/1.jpg' , 'static.tumblr/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 *.breaktaker/* // @match *.imageshack.us/* // @match static.tumblr/* // @match withfriendship/images/* // ==/UserScript== var urlsToLoad = [ 'www.breaktaker/albums/pictures/animals/BigCat.jpg' , 'img375.imageshack.us/img375/8105/bigcats34ye4.jpg' , 'withfriendship/images/g/33769/1.jpg' , 'static.tumblr/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]; }

更多推荐

如何重定向到给定站点集中的一个?

本文发布于:2023-11-01 17:55:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   站点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!