Surfingkeys
Surfingkeys copied to clipboard
What happened to the URL incrementer?
Hello,
There used to be a way to increment the last number in the URL. Was the feature removed?
Hi just bumping this one. To give more context, I believe the key was ctrl + a
which would increase the last number in a URL by 1:
Example:
URL: https://github.com/brookhong/Surfingkeys/issues/1478
ctrl a
URL: https://github.com/brookhong/Surfingkeys/issues/1479
Is this feature removed? Can I add something to the surfingkeys config to enable it?
quick and dirty:
// increment or decrement page
var incrementPage = function(amount) {
var currURL = window.location.href;
const regex = /(\d+)$/;
var matches = currURL.match(regex);
if (matches.length > 0)
{
var lastMatch = matches.pop();
var newLocation = currURL.replace(regex, parseInt(lastMatch) + amount)
window.location = newLocation;
}
};
api.mapkey('<Ctrl-a>', 'Increment page number by 1', () => incrementPage(1));
api.mapkey('<Ctrl-x>', 'Decrement page number by 1', () => incrementPage(-1));
i have no idea of the state of the feature but anyways if it helps great
Pretty cool!
var newLocation = currURL.replace(regex, parseInt(lastMatch) + amount)
On this line, what happens if there are several numbers in different locations of the URL? Will everything that matches regex be replaced with the last Match + amount?
Ex URL: good.com/?user=122&someid=999&page=5
const regex = /(\d+)$/;
The regex contains the '$' symbol, which will match for the end of the URL only, so for good.com/?user=122&someid=999&page=5
only the value of 'page' (5) will be changed.
Also, the line if (matches.length > 0)
should be changed to if(matches)
, sorry.