Surfingkeys icon indicating copy to clipboard operation
Surfingkeys copied to clipboard

What happened to the URL incrementer?

Open janacm opened this issue 3 years ago • 1 comments

Hello,

There used to be a way to increment the last number in the URL. Was the feature removed?

janacm avatar Jun 11 '21 18:06 janacm

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?

janacm avatar May 20 '22 14:05 janacm

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

neta540 avatar Nov 22 '22 20:11 neta540

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

janacm avatar Nov 23 '22 05:11 janacm

    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.

neta540 avatar Nov 26 '22 00:11 neta540