How do I open a list of pages automatically and sequentially?

后端 未结 2 770
滥情空心
滥情空心 2020-12-10 21:55

I wish to load a list of webpages sequentially, with Greasemonkey.

var list = array (\'http://www.google.com\', \'site2\', \'site3\', \'site4\');
window.loca         


        
相关标签:
2条回答
  • 2020-12-10 22:30

    Two ways I can think of for doing this are:

    Using gm_getvalue, gm_setvalue to retrieve, store the index of current site in list to Greasemonkey's persistent memory.

    Or, using something like:

    setTimeout(function(){
        window.location.href = (list.length > list.indexOf(window.location.href)) ? list[list.indexOf(window.location.href)+1] : list[0];
    },5000)
    
    0 讨论(0)
  • 2020-12-10 22:44

    This approach, for Chrome, will also work in Greasemonkey.

    Put your sites in an array, like that, but you must also set your @include, @exclude, and @match directives to fire on the appropriate sites.

    Putting it all together, here's a complete script:

    // ==UserScript==
    // @name        Multipage, MultiSite slideshow of sorts
    // @include     http://google.com/*
    // @include     http://site2/*
    // @include     http://site3/*
    // @include     http://site4/*
    // @grant       GM_addStyle
    // ==/UserScript==
    /*- The @grant directive is needed to work around a major design
        change introduced in GM 1.0.
        It restores the sandbox.
    */
    
    var urlsToLoad  = [
        'http://google.com/'
        , 'http://site2/somepage/'
        , 'http://site3/somepage/'
        , 'http://site4/somepage/'
    ];
    
    /*--- Since many of these sites load large pictures, Chrome's and 
        Firefox's injection may fire a good deal before the image(s) 
        finish loading.
        So, insure script fires after load:
    */
    window.addEventListener ("load", FireTimer, false);
    if (document.readyState == "complete") {
        FireTimer ();
    }
    //--- Catch new pages loaded by WELL BEHAVED ajax.
    window.addEventListener ("hashchange", FireTimer,  false);
    
    function FireTimer () {
        setTimeout (GotoNextURL, 5000); // 5000 == 5 seconds
    }
    
    function GotoNextURL () {
        var numUrls     = urlsToLoad.length;
        var urlIdx      = urlsToLoad.indexOf (location.href);
        urlIdx++;
        if (urlIdx >= numUrls)
            urlIdx = 0;
    
        location.href   = urlsToLoad[urlIdx];
    }
    
    0 讨论(0)
提交回复
热议问题