public
Last active

  • Download Gist
incre-decre-url.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
key.setViewKey('>', function (ev, arg) {
let pattern = /(.*?)([0]*)([0-9]+)([^0-9]*)$/;
let url = content.location.href;
let digit = url.match(pattern);
 
if (digit[1] && digit[3])
{
let len = digit[3].length;
let next = +digit[3] + (arg ? arg : 1);
content.location.href = digit[1] + (digit[2] ||"").slice(next.toString().length - len) + next + (digit[4] ||"");
}
}, 'Increment last digit in the URL');
key.setViewKey('<', function (ev, arg) {
let pattern = /(.*?)([0]*)([0-9]+)([^0-9]*)$/;
let url = content.location.href;
let digit = url.match(pattern);
 
if (digit[1] && digit[3])
{
let len = digit[3].length;
let next = +digit[3] - (arg ? arg : 1);
content.location.href = digit[1] + (digit[2] ||"").slice(next.toString().length - len) + next + (digit[4] ||"");
}
}, 'Decrement last digit in the URL');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.