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

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2025/12/24 12:13:53
🔄 下次更新时间:2025/12/24 13:13:53
手动刷新缓存

Darken

Add menuitem into browser context menu to darken the web page. For Firefox 11.0 and newer only.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

公众号二维码

扫码关注【爱吃馍】

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

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

公众号二维码

扫码关注【爱吃馍】

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

/*
    Darken
    Add menuitem into browser context menu to darken the web page.
    Compatibility: Firefox 11.0 or newer.
    Copyright (C) 2012 LouCypher

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>
*/

// ==UserScript==
// @name            Darken
// @namespace       http://userscripts.org/users/12
// @description     Add menuitem into browser context menu to darken the web page. For Firefox 11.0 and newer only.
// @version         3.0.1
// @author          LouCypher
// @contributor     luckymouse (CSS)
// @license         GPL
// @homepageURL     https://greasyfork.org/scripts/14
// @supportURL      https://greasyfork.org/scripts/14/feedback
// @resource        css https://raw.github.com/LouCypher/userscripts/master/darken/darken.css
// @resource        license https://raw.github.com/LouCypher/userscripts/master/licenses/GPL/LICENSE.txt
// @include         *
// ==/UserScript==

if (frameElement) return;

const STYLE_ID = "userscript-darken-style";
var isDark = sessionStorage.getItem("dark-site");
if (isDark) darken();

if (!(document.head && document.body)) return;
var menu = document.body.appendChild(document.createElement("menu"));
var html = document.documentElement;
if (html.hasAttribute("contextmenu")) {
  // We don't want to override web page context menu if any
  var contextmenu = $("#" + html.getAttribute("contextmenu"));
  contextmenu.appendChild(menu); // Append to web page context menu
} else {
  html.setAttribute("contextmenu", "userscript-darken-context-menu");
}

menu.outerHTML = '<menu id="userscript-darken-context-menu"\
                        type="context">\
                    <menuitem id="userscript-darken-menuitem"\
                              type="checkbox"\
                              label="Darken">\
                    </menuitem>\
                  </menu>';

if ("contextMenu" in html && "HTMLMenuItemElement" in window) {
  var menuitem = $("#userscript-darken-menuitem");
  if (isDark) menuitem.setAttribute("checked", "true");
  // Executed on clicking a menuitem
  menuitem.addEventListener("click", toggleDarken, false);
}

function darken() {
  var style = $("head").appendChild(document.createElement("style"));
  style.id = STYLE_ID;
  style.textContent = GM_getResourceText("css");
  sessionStorage.setItem("dark-site", true);
}

function toggleDarken() {
  var x = pageXOffset;
  var y = pageYOffset
  var styleNode = document.getElementById(STYLE_ID);
  if (styleNode) {
    styleNode.parentNode.removeChild(styleNode);
    sessionStorage.removeItem("dark-site");
  } else {
    darken();
  }
  scrollTo(x, y); // Restore scroll positions
}

function $(aSelector, aNode) {
  return (aNode || document).querySelector(aSelector);
}