Hallo. I have a script that automatically detects tumblr images that aren't
at their maximum available size, and then directs me to the bigger image.
It works fine, but only if I open the image by following an url; if I right
click on the image and click "View Image" it doesn't trigger the script
until I refresh the page. Is there a way to fix this?
Here's my code (it could probably be better):
var imageUrl = content.document.location.href;
function myCallBack(url, result) {
console.log(result);
if (result === "success") {
console.log(urlBig);
window.location.href = urlBig;}
}
function testImage(url, callback, timeout) {
timeout = timeout || 5000;
var timedOut = false, timer;
var img = new Image();
img.onerror = img.onabort = function() {
if (!timedOut) {
clearTimeout(timer);
callback(url, "error");
}
};
img.onload = function() {
if (!timedOut) {
clearTimeout(timer);
callback(url, "success");
}
};
img.src = url;
timer = setTimeout(function() {
timedOut = true;
callback(url, "timeout");
}, timeout);
}
var urlBig = imageUrl.replace(/_..0/g,"_1280");
console.log(urlBig);
if (imageUrl.indexOf("1280") === -1 ) {
console.log(urlBig, "big");
testImage(urlBig, myCallBack, 1000);}
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.