I found this and was able to do what I initially wanted. Javascript | Link/Bookmarklet to replace current window location
javascript:(function(){var loc=location.href;loc=loc.replace('gp/product','dp'); location.replace(loc)})()
Which was to change an amazon url from the product link to the dude perfect link.
It turns this url: https://www.amazon.com/gp/product/B01NBKTPTS/
into this url: https://www.amazon.com/dp/B01NBKTPTS/
I would like to take this a step further. Is there a way to do the above switch and then also remove the string of variables after the ? essentially cleaning up
to
https://www.amazon.com/dp/B01NBKTPTS/
Thanks!
You've almost done it yourself!
To do the second part you can use
split
on your/?
string (i.e. URL).In our case that will give you an array with two elements: the first element stores everything BEFORE the
/?
(reference [0], that's what we can use), and the other stores everything AFTER (reference [1], not needed for us)In addition, you shouldn't forget to escape the special character
/
this way:\/
.So here is the final working bookmarklet code to get the first URL part before
/?
letters, withgd/product
replaced bydp
: