If I find that websites are taking too much time and pulling my focus, I use an extension to block the sites and enter a password to open them.
In many cases, while entering the password, I can think about whether it's really necessary to open the site, such as YouTube or my local newspaper's page.
This has helped me a lot to not go into the rabbit hole.