No Animations

Clear all animations on websites

当前为 2023-10-13 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        No Animations
// @namespace   No Animations Script
// @version     2.4
// @description Clear all animations on websites
// @author      Nameniok
// @match       *://*/*
// @license     MIT
// @grant       GM_addStyle
// @grant       unsafeWindow
// ==/UserScript==

const isSameOrigin = (url) => {
  const currentOrigin = window.location.origin;
  return url.startsWith(currentOrigin);
};

GM_addStyle(`
  * {
    transition: none !important;
    transition-property: none !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
    transition-timing-function: initial !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    animation-delay: none !important;
    animation-duration: none !important;
    -webkit-animation-delay: 0 !important;
    -webkit-animation-duration: 0 !important;
    -moz-animation-delay: 0 !important;
    -moz-animation-duration: 0 !important;
    -ms-animation-delay: 0 !important;
    -ms-animation-duration: 0 !important;
    -o-animation-delay: 0 !important;
    -o-animation-duration: 0 !important;
    scroll-behavior: auto !important;
    marquee-style: none !important;
    -moz-scroll-behavior: auto !important;
    -moz-marquee-style: none !important;
  }

  *::before, *::after, *::hover, *::active {
    transition: none !important;
    transition-property: none !important;
    transition-duration: 0s !important;
    transition-timing-function: initial !important;
    -webkit-transition: none !important;
    animation-delay: none !important;
    animation-duration: none !important;
    -webkit-animation-delay: 0 !important;
    -webkit-animation-duration: 0 !important;
    -moz-animation-delay: 0 !important;
    -moz-animation-duration: 0 !important;
    -ms-animation-delay: 0 !important;
    -ms-animation-duration: 0 !important;
    box-shadow: none;
  }

  *:before, *:after, *:hover, *:active {
    transition: none !important;
    transition-property: none !important;
    transition-duration: 0s !important;
    transition-timing-function: initial !important;
    -webkit-transition: none !important;
    animation-delay: none !important;
    animation-duration: none !important;
    -webkit-animation-delay: 0 !important;
    -webkit-animation-duration: 0 !important;
    -moz-animation-delay: 0 !important;
    -moz-animation-duration: 0 !important;
    -ms-animation-delay: 0 !important;
    -ms-animation-duration: 0 !important;
  }

  input, textarea, button, select, div, a {
    -webkit-tap-highlight-color: transparent;
  }

  img[src^="https://i.ytimg.com/an_webp/"] {
    display: none !important;
  }

  img[src*="/hqdefault.jpg"] {
    display: initial !important;
  }

  @keyframes {
    from {

    }
    to {

    }
  }
`);

const blockedUrlPrefix = 'https://i.ytimg.com/an_webp/';
const blockImageLoading = (event) => {
  const src = event.target.src || '';
  if (src.startsWith(blockedUrlPrefix) || src.endsWith('.webp')) {
    event.preventDefault();
    event.target.style.display = 'none';
  }
};

unsafeWindow.addEventListener('beforeload', blockImageLoading, true);

var videos = document.getElementsByTagName('video');
window.addEventListener('load', stopVideo, false);

function stopVideo() {
    for (var i = 0; i < videos.length; i++) {
        videos[i].pause();
        videos[i].currentTime = 0;
    }
}

function removeAnimations() {
  let animationsExist = false;

  let styleSheets = Array.from(document.styleSheets);
  styleSheets.forEach((styleSheet) => {
    if (!styleSheet.href || isSameOrigin(styleSheet.href)) {
      try {
        let cssRules = Array.from(styleSheet.cssRules);
        cssRules.forEach((rule) => {
          if (rule.type === CSSRule.KEYFRAMES_RULE) {
            let keyframes = Array.from(rule.cssRules);
            keyframes.forEach((keyframe) => {
              keyframe.style.animation = "none";
              keyframe.style.animationName = "none";
              animationsExist = true;
            });
          }
        });
      } catch (error) {
        console.error("Error accessing CSS rules:", error);
      }
    }
  });

  if (animationsExist) {
    console.log("Animations removed.");
  } else {
    console.log("No animations found to remove.");
  }
}

function deactivateFadeIn() {
  let scripts = document.querySelectorAll("script");
  let fadeInsExist = false;

  scripts.forEach((script) => {
    let scriptContent = script.textContent || script.innerText;
    if (scriptContent.includes("fadeIn(")) {
      script.textContent = scriptContent.replace(/fadeIn\([^)]*\)/g, "fadeIn(0)");
      fadeInsExist = true;
    }
  });

  if (fadeInsExist) {
    console.log("fadeIn deactivated.");
  } else {
    console.log("No fadeIn found to deactivate.");
  }
}

function updateSpecificAnimations() {
  let transitionElements = document.querySelectorAll("*");
  let animationsUpdated = false;

  transitionElements.forEach((element) => {
    let computedStyle = window.getComputedStyle(element);
    let transition = computedStyle.getPropertyValue("transition");
    if (transition.includes("flex") || transition.includes("filter")) {
      element.style.transition = transition.replace(/flex[^,]*|filter[^,]*/g, "none");
      animationsUpdated = true;
    }
  });

  if (animationsUpdated) {
    console.log("Specific animations updated.");
  } else {
    console.log("No specific animations found to update.");
  }
}

// Sprawdzamy, czy istnieją animacje, fadeIn czy konkretne animacje do zaktualizowania,
// i wywołujemy odpowiednie funkcje tylko wtedy, gdy są odpowiednie elementy na stronie.
// Funkcja, która będzie wywoływana natychmiast po załadowaniu skryptu
(function () {
  if (document.styleSheets.length > 0) {
    removeAnimations();
  }

  if (document.querySelectorAll("script").length > 0) {
    deactivateFadeIn();
  }

  if (document.querySelectorAll("*").length > 0) {
    updateSpecificAnimations();
  }
})();