Greasy Fork is available in English.

Diskusie » Žiadosť o vytvorenie

Need a script that enters a URL into the browser, then increases it by 1 each time

§
Pridaný: 25.07.2018

Need a script that enters a URL into the browser, then increases it by 1 each time

Hello! I'm looking for a script that will enter a URL and then add another number onto the end of the url in numerical order.

For example, the script wants to work on www.example.com/data/0

I'd like the script to be able to take the above and then visit

www.example.com/data/1

and then continue all the way up to

www.example.com/data/10000

and further beyond.

Does a script like this already exist out there?

§
Pridaný: 25.07.2018

Try something like this, where pressing 'n' on your keyboard should load the next page.

let path = document.location.pathname;
let currentNum = parseInt(path.substring("/data/".length), 10);

document.addEventListener('keypress', (event) => {
  if (event.key == 'n')
  {
    ++currentNum;
    window.location.replace("/data/"+currentNum);
  }
});
§
Pridaný: 02.08.2018

An alternative regex-based solution.

addEventListener('keypress', ({key:key}) => {
  if ('n' === key)
    location = location.toString().replace(/(data\/)(\d+)/, (wholeString,prefix,number)=>prefix+ ++number)
});
§
Pridaný: 04.08.2018

There're bookmarklets that'll increment & decrement - "Increases/Decreases the last number in the URL by 1": https://www.squarefree.com/bookmarklets/misc.html

Assign the bookmarklet to a bookmark, and you got a manual url adjuster.

Pridať odpoveď

Aby ste mohli pridať odpoveď, prihláste sa.