How to redirect to one out of given set of sites?

前端 未结 1 1987
独厮守ぢ
独厮守ぢ 2020-12-11 11:19

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

// ==UserScript==
// @id             fvhfy464
// @name           [udit]redirec         


        
相关标签:
1条回答
  • 2020-12-11 12:13

    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];
    }
    
    0 讨论(0)
提交回复
热议问题