I'm trying to create a bookmarklet that redirects me from a product page to the file (mp3 in this case) related to that product.
I currently have a functional bookmarklet I was testing, but it only works on the current product page and I'm trying to modify it to work on all pages in that domain.
Ex: I'm trying to redirect this (current page):
https://www.samplewebsite.com/product-title/12345.item
to here (website's sample file I'm trying to download for reference in my own library of products I own from this site)
https://string.samplehost.audio/12345.mp3
Here's what I have right now just to test the basics
javascript:(function() {window.location=window.location.toString().replace('https://www.samplewebsite.com/product-page/','https://string.samplehost.audio/').replace('.item','.mp3');})()
This is working, but only for current product page, which isn't helpful when I'm trying to make the bookmark work on the entire domain regardless of what product I'm looking at. I'm trying to figure out a way to always remove the bolded portion in this example which is unique to each product https://www.samplewebsite.com/**product-title**/
I know this shouldn't be too difficult since the product number on the URL and the name of the mp3 on the host site are always the same. I don't know if it would be best to replace everything except the number of the product, then add the correct redirect URL before it and .mp3 after, or if there's some easier way to do this.
Or is there a way to replace everything before the last forward slash of the url instead? Then I could use a simple replace function to replace ".item" with ".mp3"