🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/05 04:49:40
🔄 下次更新时间:2026/01/05 05:49:40
手动刷新缓存

[SNOLAB] Alt + i to invert color of Images / Videos Color

Invert page color by Alt+i, combo with Ctrl+Windows+C to invert the color of whole screen, you can enjoy the real night mode in windows.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name             [SNOLAB] Alt + i to invert color of Images / Videos Color
// @name:zh-CN       [SNOLAB] Alt + i 反转图片/视频颜色
// @name:es          [SNOLAB] Alt + i para invertir el color de imágenes/videos
// @name:fr          [SNOLAB] Alt + i pour inverser la couleur des images/vidéos
// @name:ru          [SNOLAB] Alt + i для инвертирования цвета изображений/видео
// @name:ar          [SNOLAB] Alt + i لعكس ألوان الصور/الفيديوهات
// @namespace        [email protected]
// @version          1.1.0
// @description      Invert page color by Alt+i, combo with Ctrl+Windows+C to invert the color of whole screen, you can enjoy the real night mode in windows.
// @description:zh-CN 按 Alt+i 反转页面颜色,配合 Ctrl+Windows+C 反转整个屏幕颜色,享受真正的夜间模式。
// @description:es   Invierte el color de la página con Alt+i, combina con Ctrl+Windows+C para invertir el color de toda la pantalla, puedes disfrutar del modo nocturno real en Windows.
// @description:fr   Inversez la couleur de la page avec Alt+i, combinez avec Ctrl+Windows+C pour inverser la couleur de tout l'écran, profitez du vrai mode nuit sous Windows.
// @description:ru   Инвертируйте цвет страницы с помощью Alt+i, комбинируйте с Ctrl+Windows+C для инвертирования цвета всего экрана, наслаждайтесь настоящим ночным режимом в Windows.
// @description:ar   اعكس ألوان الصفحة بـ Alt+i، ادمج مع Ctrl+Windows+C لعكس ألوان الشاشة بالكامل، استمتع بالوضع الليلي الحقيقي في Windows.
// @author           [email protected]
// @match            *://*/*
// @contributionURL  https://snomiao.com/donate
// @supportURL       https://github.com/snomiao/media-color-invert/issues
// @grant            GM.getValue
// @grant            GM.setValue
// @run-at           document-start
// ==/UserScript==

main();
function main() {
  const ac = new AbortController();
  globalThis.MediaColorInvert?.abort();
  globalThis.MediaColorInvert = ac;

  const signal = ac.signal;
  // watch
  const debouncedScan = debounce(scan, 8); // Adjust the delay (300ms) as needed
  scan();
  // new MutationObserver((mutationList, observer) => {
  //   mutationList.forEach((mutation) =>
  //     mutation.addedNodes.forEach((e) => scan(e))
  //   );
  // }).observe(document.body, { subtree: true, childList: true });
  window.addEventListener("focus", () => scan(), { signal });

  // toggle
  window.addEventListener("keydown", (e) => isAltI(e) && toggle(), { signal });
}

async function toggle() {
  await setInvert(!(await getInvert()));
  await scan();
}
async function scan() {
  const invert = await getInvert();
  const textNode = document.createTextNode(`
.body{
filter: hue-rotate(180deg);
}
video,img{
filter: invert(1);
}
svg:not(:has(svg)){
filter: hue-rotate(180deg);
}
`);
  const style = document.createElement("style");
  style.appendChild(textNode);
  style.id = "media-color-invert";
  const s = document.head?.querySelector("&>#media-color-invert");

  if (s && !invert) s.remove();
  if (!s && invert) document.head.appendChild(style);
}

async function getInvert() {
  return (await globalThis.GM?.getValue("media-color-invert")) ?? false;
}
async function setInvert(i) {
  return await globalThis.GM?.setValue("media-color-invert", i);
}

function isAltI(e) {
  return e.altKey && !e.metaKey && !e.shiftKey && !e.ctrlKey && e.code === "KeyI";
}

function debounce(func, delay) {
  let timeout;
  return function (...args) {
    const context = this;
    clearTimeout(timeout);
    timeout = setTimeout(() => func.apply(context, args), delay);
  };
}