1

I've got a Greasemonkey script (written by another coder - Brock Adams) that loads sequentially the pages contained in the array at the beginning of the code. How to open a list of pages automatically and sequentially?

   // ==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];
}

The problem comes when I have 2 pages of the same website to be loaded sequentially: the script stops working because the website uses AJAX in order to have a faster loading of its pages.

How can I force this script to fully reload pages?

As you can see he already tried:

//--- Catch new pages loaded by WELL BEHAVED ajax. 
window.addEventListener ("hashchange", FireTimer,  false);

to solve this issue, but it doesn't work as expected.

In particular the site that gives me this issue is ink361.com. I've created a jsFiddle of an example of his source: http://jsfiddle.net/XjjfK/

Thanks in advance.

Community
  • 1
  • 1
Giorgio
  • 1,603
  • 5
  • 29
  • 52
  • 1
    Giorgio, what is your browser version? What is your Greasemonkey version? And, list at least 2 URL's that exhibit this behavior, we need to see these in **detail**. ... Finally, does the script change at least one page at that site? (It should change 1 before stopping.) – Brock Adams Sep 05 '12 at 20:06
  • I'm on Firefox 14.0.1 for mac osx 10.5.8. Greasemonkey 1.0 updated to 3 Sep 2012. Yes the script changes one page. When the second page has been loaded it doens't work anymore. If the pages of this website are alternated with another one it works correctly: problemsite1 - another site - problemsite2 --> go ahead. I can list as many URL as you need but they all need to be logged in to properly be displayed: Thanks for support. – Giorgio Sep 05 '12 at 21:15
  • Example of URLs that generate this problem: http://ink361.com/#/users/206053596/photos http://ink361.com/#/users/199101377/photos http://ink361.com/#/users/203767882/photos – Giorgio Sep 05 '12 at 21:15

1 Answers1

2

I can't login, but the script worked perfectly for me.
I installed the script exactly as below, and it cycled between those 3 ink361.com pages, just as expected.

Some things for you to do/check:

  1. Are you using your other script (or ANY other GM script) on the same pages?

  2. When you are browsing ink361.com, what does the Greasemonkey menu show? GM menu
    GM menu results

  3. It sounds like the installed script doesn't have the hashchange code -- which should work on that site, since it does update the hashtags.

    1. Uninstall the script.
    2. Restart Firefox.
    3. Reinstall the script.

  4. Post the exact, unedited script - that you are using - at pastebin.com, and link to it here.

  5. Uninstall any other script for ink361.com, and install just the script below.
    Does it work?
    If not, post the console log, or Firebug's log, at pastebin.com.

// ==UserScript==
// @name        _del me
// @namespace   _pc
// @include     http://ink361.com/*
// @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.
*/
console.log ("Start: ", Date ());

var urlsToLoad  = [
    'http://ink361.com/#/users/206053596/photos'
    , 'http://ink361.com/#/users/199101377/photos'
    , 'http://ink361.com/#/users/203767882/photos'
];

/*--- 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 (zParam) {
    console.log ("Fire: ", zParam);
    console.log (Date ());
    setTimeout (GotoNextURL, 5000); // 5000 == 5 seconds
}

function GotoNextURL () {
    var numUrls     = urlsToLoad.length;
    var urlIdx      = urlsToLoad.indexOf (location.href);
    urlIdx++;
    if (urlIdx >= numUrls)
        urlIdx = 0;

    console.log ("Loading: ", urlsToLoad[urlIdx]);
    location.assign (urlsToLoad[urlIdx]);
}
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • I had the other script enabled and it prevent this one to work correctly! :) Now it's working as expected. Thank you man, you're a genious, seriously. – Giorgio Sep 06 '12 at 07:41
  • You're welcome; glad you got it working. Please also mark [the other question](http://stackoverflow.com/a/12261238/331508) as complete. – Brock Adams Sep 06 '12 at 08:00