2

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);

But it doesn't work.

(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.

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
adi
  • 207
  • 1
  • 10
  • This question is not clear. You want to redirect yahoo.com to yahoo.com? Open three sites one after another? Open all at once? Just the home page? – Brock Adams Jul 06 '12 at 00:19
  • hi brock, what i want is to open multiple sites in a single tab one after another in random way with time difference of 4 seconds, for ex : if yahoo.com is opened , script redirect to any one out of these 3 sites either yahoo,google or bing . its like a screensaver of sites ,please help .:) – adi Jul 06 '12 at 14:33
  • How will the script know when to stop? (Otherwise this scheme would loop forever.) – Brock Adams Jul 06 '12 at 14:36
  • yeah , it can go forever . to stop , i just have to close the tab , and i set only those sites in include on which i want this script to work on .like a screeensaver of photos – adi Jul 06 '12 at 14:38
  • actually i want this script to create a slideshow on picture sites like flickr etc , so every time site reload a new page , a new picture will be there. – adi Jul 06 '12 at 14:47

1 Answers1

2

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];
}
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 5 star for you , u r the most helping dude for me on net – adi Jul 06 '12 at 18:27
  • hey buddy , can the script be modified such as it add random suffix[number] within a range like 1-999999 to site n open it . it makes the script really awesome. for ex: add random suffix number like 2047859 to "http://wallbase.cc/wallpaper/" n open "http://wallbase.cc/wallpaper/2047859". i think it can make the script work like stumbleupon addon – adi Jul 06 '12 at 23:31
  • Do you want to keep switching to a random suffix all on the same site?... or on multiple domains? Probably best to open a new question and be as specific as possible. Link and describe that stumbleupon addon -- for those of us who don't use stumbleupon at all. – Brock Adams Jul 07 '12 at 00:53
  • sorry for late reply, some image sites have new picture everytime when we reload them [like failjudge.com] but in some we can get new images only by adding number as suffix like [wallbase.cc] . so the suffix thing can be set up such that it work on all such domains [like wallbase.cc] n about those domains [like failjudge] , script just simply reloads them. sorry if i cant put my query in proper n explained way , its just i am miles away from understanding such complicated stuff.i know all these knowledge is cool but it takes time n i hope u guys r there to help guys like me. – adi Jul 07 '12 at 16:18
  • about stumbleupon addon , it is a breeze for internet users . i highly recommend it for u and other guys pleasure. - open this url "http://www.stumbleupon.com/su/#url=" n click stumble to see cool random sites on net - link to firefox addon "https://addons.mozilla.org/en-US/firefox/addon/stumbleupon/?src=search" - link to chrome addon "https://chrome.google.com/webstore/detail/kcahibnffhnnjcedflmchmokndkjnhpg" – adi Jul 07 '12 at 16:20
  • Okay, please create a new question for the suffix thing. The question can/should refer to this Q. Also, are you using the "in order" or the random version of the answer? – Brock Adams Jul 07 '12 at 18:48
  • new question - http://stackoverflow.com/questions/11401939/how-to-make-a-script-open-random-pageimage-on-site-like-wallbase-cc-by-using-o – adi Jul 09 '12 at 19:39