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와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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');
}