No single tool, script, device or system will stop this.

In fact, blocking tools can actually make this worse. Using a blocking tool is tacitly saying "I can't control myself. I need to hand control to something outside of myself" This basically reinforces the belief that you cannot control your problematic consumption.

You need strategies that reinforce the opposite belief: You are in control of your usage.

I recommend looking into books like Feeling Good and Feeling Great. Get a greater understanding of your emotional state and work out how that feeds into your social media usage.

There are some tools that are useful. The first is time tracking tools. They let you look back on your day and work out how you spent your time. What are the patterns of your usage. Do you always end up struggling after lunch? Or in the evening? What are your triggers?

While I wouldn't recommend blocking sites completely, blocking the most distracting parts of sites can be useful. If you're studying from youtube videos, using a plugin that blocks comments and suggested videos is extremely useful. This means you will no longer catch a glimpse of a thumbnail of something interesting and go off task.

Overall, you have to tackle your emotions and your beliefs about yourself.