No Animations

Clear all animations on websites

目前為 2023-10-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

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

const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
  * {
    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;
  }

  @keyframes {
    from {

    }
    to {

    }
}

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

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

// Add styles to head
document.head.appendChild(style);

// Blocking animated images from YouTube
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);


//Pause all HTML5 videos on load (https://greasyfork.org/en/scripts/6487-pause-all-html5-videos-on-load/code)
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;  // Poprawione odwołanie do currentTime
    }
}


// Function to remove animations from keyframes animation rules
function removeAnimations() {
 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";
            });
          }
        });
      } catch (error) {
        console.error("Error accessing CSS rules:", error);
      }
    }
  });
}


// Find and deactivate fadeIn animations
function deactivateFadeIn() {
 let scripts = document.querySelectorAll("script");
  scripts.forEach((script) => {
    let scriptContent = script.textContent || script.innerText;
    if (scriptContent.includes("fadeIn(")) {
      script.textContent = scriptContent.replace(/fadeIn\([^)]*\)/g, "fadeIn(0)");
    }
  });
}

// Update specific animations
function updateSpecificAnimations() {
let transitionElements = document.querySelectorAll("*");
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");
  }
});
}

removeAnimations();
deactivateFadeIn();
updateSpecificAnimations();