Skip to content

Instantly share code, notes, and snippets.

@aont
Created March 12, 2011 10:04
Show Gist options
  • Select an option

  • Save aont/867168 to your computer and use it in GitHub Desktop.

Select an option

Save aont/867168 to your computer and use it in GitHub Desktop.
URL number operate
function to(num)
{
location.href = location.href.replace(/(\d+)([^0-9]*$)/, num.toString() + "$2");
}
function diff(d)
{
if (location.href.match(/(\d+)([^0-9]*$)/))
{
num = parseInt(RegExp.$1, 10) + d;
location.href = location.href.replace(/(\d+)([^0-9]*$)/, num.toString() + "$2");
}
undefined;
}
function to_digit(num)
{
if (location.href.match(/(\d+)([^0-9]*$)/))
{
var num_digits = RegExp.$1.length;
var num_str = num;
for (var i = num_str.length; i < num_digits; ++i) {
num_str = "0".concat(num_str);
}
location.href = location.href.replace(/(\d+)([^0-9]*$)/, num_str + "$2");
}
undefined;
}
function diff_digit(d)
{
if (location.href.match(/(\d+)([^0-9]*$)/))
{
var num_digits = RegExp.$1.length;
var num_str = (parseInt(RegExp.$1, 10) + d ).toString();
for (var i = num_str.length; i < num_digits; ++i) {
num_str = "0".concat(num_str);
}
location.href = location.href.replace(/(\d+)([^0-9]*$)/, num_str + "$2");
}
undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment