Increment Number in URL

5
1 vote
Your rating: None

Adds 1 to the numeric part of any URL, to easily navigate from:
www.example.com/screenshot_41.png
to
www.example.com/screenshot_42.png
OR
www.example.com/?page=3
to
www.example.com/?page=4

(code adopted from squarefree.com bookmarklet)

Runs in:

all frames

Script:

  var e,s;
  IB=1;
  function isDigit(c) {
    return ("0" <= c && c <= "9") 
  }
  L = location.href;
  LL = L.length;
  for (e=LL-1; e>=0; --e)
    if (isDigit(L.charAt(e))) {
      for(s=e-1; s>=0; --s)
        if (!isDigit(L.charAt(s)))
          break;
      break;
    }
  ++s;
  if (e<0)
    return;
  oldNum = L.substring(s,e+1);
  newNum = "" + (parseInt(oldNum,10) + IB);
  while (newNum.length < oldNum.length)
    newNum = "0" + newNum;
  location.href = L.substring(0,s) + newNum + L.slice(e+1);

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <strike> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is to prevent automated spam submissions, you will not see this again after registration.