How to make a script redirect only once every time an appropriate page loads?
问题 I'm writing a Tampermonkey script that I want to use to redirect from youtube.com/* to a YouTube channel address. window.addEventListener ("load", LocalMain, false); function LocalMain () { location.replace("https://www.youtube.com/channel/*"); } When the script is running it redirects to the channel URL but then keeps running and continuously redirects . 回答1: You need to check if the current pathname includes channel before reassigning a new href function LocalMain () { if(!location.pathname