TikTok - Remove distractions

Remove distractions on TikTok

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        TikTok - Remove distractions
// @description Remove distractions on TikTok
// @version  1.2
// @grant    none
// @include	*://tiktok.com/*
// @include	*://*.tiktok.com/*
// @license     GPL v3
// @author      @incognico
// @namespace   https://greasyfork.org/users/931787
// ==/UserScript==

const selectors = [
  '[data-e2e="nav-live"]', // Live tab
  '[data-e2e="nav-foryou"]', // For you tab
  '[data-e2e="nav-explore"]', // Explore tab
  '[class*="-DivDiscoverContainer"]', // Discover section
  '[class*="-DivUserContainer"]:has([data-e2e="suggest-accounts"])', // Suggested accounts in sidebar (needs about:config layout.css.has-selector.enabled for now)
  '[data-e2e="recharge-entrance"]', // Get coins in profile menu
  '[data-e2e="live-studio-entrance"]', // Live Studio in profile menu
  '[class*="-StyledShareIcon"]', // Share icon on profile page
  '[data-e2e="upload-icon"]', // Upload button
];

const hide = (selector) => {
  const node = document.querySelector(selector);
  if (node) {
    node.style.display = 'none';
  }
};

const redirectClickEvent = (event) => {
  event.preventDefault();
  event.stopImmediatePropagation();
  const followingButton = document.querySelector('[data-e2e="nav-following"]');
  if (followingButton) {
    followingButton.click();
  } else {
    window.location.pathname = '/following';
  }
};

const listeners = [];
const redirect = () => {
  // replace home links click to following button
  const links = document.querySelectorAll('[href="/"]');
  links.forEach(link => {
    if (!listeners.includes(link)) {
      listeners.push(link);
      link.addEventListener('click', redirectClickEvent, true);
    }
  });
}

window.setTimeout(
  function check() {
    selectors.forEach(hide);
    redirect();
    window.setTimeout(check, 250);
  }, 250
);

// redirect from home live or home with country code
const { pathname } = window.location;
if (pathname === '/' || pathname === '/live' || pathname === '/explore' || pathname.match(/\/[a-z]{2}$/)) {
  window.location.replace('/following');
}