Handy Image

Shows just fullsize Image with hotkeys & without pop-ups on many image-hosting sites

< Feedback on Handy Image

Question/comment

FFW
§
Posted: 2015-06-12
Edited: 2015-06-12

Two possibilities

Is there a way to tell the script to try and if it fails to find an image try another.

example i.src = i.content.replace('thumb','org') if it fails try i.src = i.content.replace('thumb','hd')

OwynAuthor
§
Posted: 2015-06-12

there is no image finding in lines you gave here, those just replace part of content, 'finding' an image isn't about guessing it - it's about actually finding it - look for it in pages source and make a way for script to pick it.

FFW
§
Posted: 2015-06-12
Edited: 2015-06-12

That was just the last part :P

case "example.com":
    i = document.head.querySelector('meta[property="og:image"]');
    if(i){
               i.src = i.content.replace('thumb','org'); // if it fails  to build the image try 
                                            // i.src = i.content.replace('thumb','hd')
            }
    break;

Like building an array of possibilities and going through it. Is it possible?

§
Posted: 2015-06-12
i.tryIndex = 0;
i.rules = [['thumb', 'org'], ['thumb', 'hd']];

function nextRule() {
  var index = i.tryIndex++;
  if (index >= i.rules.length) {
    console.error('I tried, give up.');
    return ;
  }
  i.src = i.content.replace(i.rules[index][0], i.rules[index][1]);
};
i.onerror = nextRule;
nextRule ();

Not tested though... Don't know if it will fire standard onerror event.

FFW
§
Posted: 2015-06-12
Edited: 2015-06-12

@JixunMoe Doesn't seem to be working. Would always use the first option in the array. Thank you for writing that though :)

Post reply

Sign in to post a reply.