DatafetchPro
    1776835664301_hv4ayh.webp
    Apr 22, 20265 min read16 views

    X/Twitter Focus Mode Script for Clean Feed

    Clean your X (Twitter) feed with this Tampermonkey script. Hide distractions, highlight links, and stay focused on what matters.

    If you’ve been using X (Twitter) for a while, you already know how distracting it can get. Trending panels, sidebars, random suggestions—it all pulls your attention away from what you actually came for.




    So instead of complaining about it, I built a simple fix.

    This Focus Mode script is a lightweight solution that removes the noise and keeps your timeline clean. No heavy extensions, no complicated setup—just install it in Tampermonkey, and you’re good to go.

    What this script actually does

    The goal is simple: less distraction, more concentration.

    • Hide sidebar & trending
    • Reduces extra UI clutter that breaks your flow
    • Highlights links inside posts for easier spotting
    • Keeps everything focused on the main timeline

    It doesn’t try to redesign the platform. It just makes it usable again.

    Why this matters

    When you’re doing research, scraping data, or even just browsing with intent, distractions cost time. A clean interface helps you:

    • Accelerate processing of content
    • Don’t make them click too much
    • Focus on useful information

    If you’re into automation or scraping workflows, this becomes even more valuable. Less noise = cleaner extraction logic and better efficiency.

    How to use it

    1. Install Tampermonkey in your browser
    2. Add the script (you’ll find it below this article)
    3. Open X/Twitter
    4. Toggle Focus Mode anytime from the toolbar

    That’s it. No configs, no setup headaches.

    Small feature, big impact

    Sometimes the best tools are the simplest ones. This script doesn’t try to do everything—it just fixes one annoying problem really well.

    If you spend hours on X for research, lead generation, or automation tasks, this will quietly save you time every single day.


    // ==UserScript==
    // @name X/Twitter Focus Mode
    // @namespace http://tampermonkey.net/
    // @version 1.1
    // @description Hide sidebars, highlight links, and keep focus on main timeline
    // @match https://x.com/*
    // @match https://twitter.com/*
    // @grant none
    // @run-at document-idle
    // ==/UserScript==

    (function () {
    'use strict';

    const STYLE_ID = 'tm-x-focus-style';
    const TOOLBAR_ID = 'tm-x-focus-toolbar';

    const css = `
    [data-testid="sidebarColumn"] { display: none !important; }
    [data-testid="DMDrawer"] { display: none !important; }
    [aria-label="Timeline: Trending now"] { display: none !important; }
    [aria-label="Timeline: Explore"] { display: none !important; }

    article a[href^="http"],
    article a[href^="https"] {
    background: rgba(29, 155, 240, 0.12) !important;
    color: #1d9bf0 !important;
    border-radius: 4px !important;
    padding: 0 3px !important;
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    }
    `;

    function ensureStyle() {
    if (document.getElementById(STYLE_ID)) return;
    const style = document.createElement('style');
    style.id = STYLE_ID;
    style.textContent = css;
    document.head.appendChild(style);
    }

    function highlightLinks(root = document) {
    root.querySelectorAll('article a[href]').forEach(a => {
    if (a.dataset.tmXDone) return;
    a.dataset.tmXDone = '1';
    if (a.href.startsWith('http')) {
    a.style.background = 'rgba(29, 155, 240, 0.12)';
    a.style.color = '#1d9bf0';
    a.style.borderRadius = '4px';
    a.style.padding = '0 3px';
    a.style.textDecoration = 'underline';
    a.style.textDecorationThickness = '2px';
    }
    });
    }

    function applyFocusMode(on) {
    document.documentElement.classList.toggle('tm-x-focus-on', on);
    document.body.classList.toggle('tm-x-focus-on', on);
    localStorage.setItem('tm_x_focus', on ? '1' : '0');
    }

    function ensureToolbar() {
    if (document.getElementById(TOOLBAR_ID)) return;

    const bar = document.createElement('div');
    bar.id = TOOLBAR_ID;
    bar.className = TOOLBAR_ID;
    bar.innerHTML = `
    <button id="tmToggle">Toggle Focus</button>
    <button id="tmRefresh" class="secondary">Refresh Links</button>
    `;
    document.body.appendChild(bar);

    document.getElementById('tmToggle').addEventListener('click', () => {
    const enabled = !document.body.classList.contains('tm-x-focus-on');
    applyFocusMode(enabled);
    });

    document.getElementById('tmRefresh').addEventListener('click', () => {
    highlightLinks(document);
    });
    }

    function init() {
    ensureStyle();

    const enabled = localStorage.getItem('tm_x_focus') !== '0';
    applyFocusMode(enabled);

    ensureToolbar();
    highlightLinks(document);

    const obs = new MutationObserver(() => {
    highlightLinks(document);
    ensureToolbar();
    });

    obs.observe(document.documentElement, { childList: true, subtree: true });
    }

    if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
    } else {
    init();
    }
    })();
    0