The way the author managed to reduce the impact of this habit was to remove the cue for wasting time by memorizing syntax. Congrats on that! This seems like a pretty demanding solution, though.
Perhaps a very simple way forward would be to employ a site blocker on distracting sites during work hours.
Beyond that the author might regulate their work hours so that they have limited time to get things done and avoid burnout from long days.
They also might consider using a pomodoro technique, so that their brain can alternate between focused and relaxed attention. Setting boundaries around when it’s time to focus and introducing a purposeful schedule of relaxing breaks helps keep one from falling victim to bad habits when your brain needs a moment to relax.