So, I wrote a script that loads images one at a time in a new tab... Got a stop button to work thanks to Brock over HERE...
Then I broke it adding in the counter that I had written in while waiting for an answer to that question.
I can't see any reason that should have broke it... help please?
My Script:
var box = document.createElement ('div');
box.id = 'mySelectBox';
GM_addStyle (
' #mySelectBox { ' +
' background: white; ' +
' border: 2px solid red; ' +
' padding: 4px; ' +
//' position: absolute; ' +
' position: fixed; ' +
' top: 8px; left: 8px; ' +
' max-width: 400px; ' +
' } '
);
document.body.appendChild (box);
box.innerHTML = '';
var searchButton = document.createElement ('div');
searchButton.className = 'mySearchButton';
searchButton.textContent = 'Open';
GM_addStyle (
' .mySearchButton { ' +
' background: #aaa; ' +
' border: 1px solid #777; ' +
' padding: 1px; ' +
' margin-left: 8px; ' +
' float: right; ' +
' cursor: pointer; ' +
' } '
);
box.insertBefore (searchButton, box.nextSibling);
var stopButton = document.createElement ('div');
stopButton.className = 'myStopButton';
stopButton.textContent = 'Stop';
GM_addStyle (
' .myStopButton { ' +
' background: #aaa; ' +
' border: 1px solid #777; ' +
' padding: 1px; ' +
' margin-left: 8px; ' +
' float: right; ' +
' cursor: pointer; ' +
' } '
);
box.insertBefore (stopButton, box.nextSibling);
var closeButton = document.createElement ('div');
closeButton.className = 'myCloseButton';
closeButton.textContent = 'X';
GM_addStyle (
' .myCloseButton { ' +
' background: #aaa; ' +
' border: 1px solid #777; ' +
' padding: 1px; ' +
' margin-left: 8px; ' +
' float: right; ' +
' cursor: pointer; ' +
' } '
);
box.insertBefore (closeButton, box.firstChild);
closeButton.addEventListener ('click', function () {
box.parentNode.removeChild (box);
}, true);
var mytable = document.getElementById
('lair-sort-pets').getElementsByTagName ('img');
var linksToOpen = [];
var mywin2 = null;
var okayToOpenLinks = true;
searchButton.addEventListener ('click', openpics);
stopButton.addEventListener ('click', stopLinkSequence);
function openpics () {
okayToOpenLinks = true;
if (linksToOpen.length === 0) {
for (var J = 0, L = mytable.length; J < L; J++) {
linksToOpen.push (mytable[J].src); //-- Add URL to list
}
}
openLinksInSequence ();
};
original = box.innerHTML
function stopLinkSequence () {
okayToOpenLinks = false;
}
function openLinksInSequence () {
k = linksToOpen.length - 1
if (mywin2) {
mywin2.close ();
mywin2 = null;
}
if (okayToOpenLinks && linksToOpen.length) {
var link = linksToOpen.shift ();
mywin2 = window.open (link, "my_win2");
box.innerHTML = '<center>Links left</center><br>' + '<center>' + k + '</center><br>' + original;
mywin2.addEventListener ('load', openLinksInSequence, false);
}
}
If I comment out this line it works again (except no status counter):
box.innerHTML = '<center>Links left</center><br>'+'<center>'+k+'</center><br>'+original;
WHY?
HERE is a possible target page for the Greasemonkey script.