Know that you are alone. Many have suffered from this terrible affliction, and you won’t be the last. Me included.
Do not neglect the sacrament of reconciliation (confession). This is your lifeblood. Each and every time you commit the sin, go to confession. Try to go to the same priest regularly, someone you know and trust well and whom knows you in return.
Partake of the Eucharist as often as you can (though, not while you’re in the state of mortal sin).
Pray throughout the day for God to guide your thoughts to holiness and purity.
Limit your internet use. If you’re tempted to go to impure websites while online, it might be time to curb your use significantly. If you have a computer in your room, take it out. Put parental software on that prevents you from going to said websites.
Put pictures of saints and the Blessed Mother where you might be tempted to commit the sin.
And finally, DO NOT DESPAIR. If you find yourself committing the sin or in a state of mortal sin again, do not give up or despair. It is nearly impossible to quit cold turkey. It will be a long fight. But eventually you’ll see progress. You’ll regress from every day to once a week, to once every few weeks, to once every couple months, until finally you have self-mastery. Do not give up the battle.
I’ll be praying for you and all that may be suffering from this affliction!