您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Pause and resume GIF and WebP animations on right-click
// ==UserScript== // @name GifPause: Pause and Resume annoying GIF Animations on Right Click // @author cemiu // @namespace https://cemiu.net/ // @license MIT // @version 1.4 // @description Pause and resume GIF and WebP animations on right-click // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; const ORIGINAL_SRC_ATTR = 'data-original-src'; function isAnimatedImage(target) { return target.hasAttribute(ORIGINAL_SRC_ATTR) || target.src.endsWith('.gif') || target.src.endsWith('.webp'); } async function toggleAnimation(target) { if (target.hasAttribute(ORIGINAL_SRC_ATTR)) { target.src = target.getAttribute(ORIGINAL_SRC_ATTR); target.removeAttribute(ORIGINAL_SRC_ATTR); } else { let response = await fetch(target.src, { mode: 'cors' }); let blob = await response.blob(); let img = new Image(); img.src = URL.createObjectURL(blob); img.onload = () => { let canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; canvas.getContext('2d').drawImage(img, 0, 0); target.setAttribute(ORIGINAL_SRC_ATTR, target.src); target.src = canvas.toDataURL('image/png'); URL.revokeObjectURL(img.src); }; } } document.addEventListener('contextmenu', event => { let target = event.target; if (target.tagName === 'IMG' && isAnimatedImage(target)) { event.preventDefault(); toggleAnimation(target); } }, false); })();