I have this script that peels off the tracking data from an Amazon URL and strips it down to the basics.
Tell application "Google Chrome"
set theUrl to URL of active tab of window 1
set splitCharacters to "?"
set splitOffset to (offset of splitCharacters in theUrl) + (count splitCharacters) - 1
set newURL1 to text 1 thru splitOffset of theUrl
set AppleScript's text item delimiters to "p/"
set itemNumber to text item 2 of newURL1
set newUrl to "https://www.amazon.com/dp/" & itemNumber
set the clipboard to newUrl
--return newUrl
set URL of active tab of window 1 to newUrl
end tell
Using the URL from a FB post: https://www.amazon.com/Squeaky-Aggressive-Interactive-Squeaker-Indestructible/dp/B08P1GKG4D?%2F%3Ftag=renbar-ace-20&fbclid=IwAR2DqPuwdKQ9c1EQXtJJHRlYjnq_Lzj4_mW_qoNPq6BgVs1y94cev5h07B4
the current script gives me:
https://www.amazon.com/dp/B08P1GKG4D? <----- that darn ? needs to be exterminated!
I need it to also get rid of the "?" at the end but I can't figure out how to make that happen since the characters prior to the ? are always different. I can't just tell it to delete the last character because sometimes that ? isn't there and I'd lose the last character of the item number. And the text past the "?" also varies. So I can't use a different character as the split point.
I know (hope?) it's more simple than I can figure out....but I just can't figure it out!