Brightness, Contrast, and Saturation Control

Adjust brightness, contrast, and saturation of a webpage

目前為 2024-12-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Brightness, Contrast, and Saturation Control
// @namespace    http://your.namespace.here/
// @version      1.4
// @description  Adjust brightness, contrast, and saturation of a webpage
// @author       tae
// @match        *://*/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        if (document.querySelector('.brightness-control-toggle')) return;

        const toggleButton = document.createElement('button');
        toggleButton.textContent = 'Adjust Filters';
        toggleButton.className = 'brightness-control-toggle';
        toggleButton.style.cssText = `
            position: fixed;
            top: 10px;
            left: 10px;
            background-color: #444;
            color: white;
            border: none;
            padding: 5px 10px;
            z-index: 2147483647;
            border-radius: 5px;
        `;
        document.body.appendChild(toggleButton);

        const controlPanel = document.createElement('div');
        controlPanel.className = 'brightness-control-panel';
        controlPanel.style.cssText = `
            position: fixed;
            top: 40px;
            left: 10px;
            background-color: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 10px;
            z-index: 2147483646;
            border-radius: 5px;
            width: 200px;
            font-family: Arial, sans-serif;
            display: none;
            overflow-y: scroll;
            max-height: 300px; /* You can adjust this value */
        `;
        document.body.appendChild(controlPanel);

        toggleButton.addEventListener('click', (event) => {
            event.stopPropagation();
            controlPanel.style.display = controlPanel.style.display === 'none' ? 'block' : 'none';
        });

        function makeDraggable(element) {
            let isDragging = false, startX, startY, initialLeft, initialTop;

            element.addEventListener('mousedown', (event) => {
                if (event.target.tagName !== 'INPUT') {
                    isDragging = true;
                    startX = event.clientX;
                    startY = event.clientY;
                    initialLeft = element.offsetLeft;
                    initialTop = element.offsetTop;
                    event.preventDefault();
                }
            });

            document.addEventListener('mousemove', (event) => {
                if (isDragging) {
                    const deltaX = event.clientX - startX;
                    const deltaY = event.clientY - startY;
                    element.style.left = `${initialLeft + deltaX}px`;
                    element.style.top = `${initialTop + deltaY}px`;
                }
            });

            document.addEventListener('mouseup', () => isDragging = false);
        }

        makeDraggable(controlPanel);

        const createSlider = (labelText, defaultValue, min, max, step, onChange) => {
            const container = document.createElement('div');
            container.style.marginBottom = '10px';

            const label = document.createElement('label');
            label.textContent = labelText;
            label.style.display = 'block';
            label.style.marginBottom = '5px';
            container.appendChild(label);

            const slider = document.createElement('input');
            slider.type = 'range';
            slider.value = defaultValue;
            slider.min = min;
            slider.max = max;
            slider.step = step;
            slider.style.width = '100%';
            slider.oninput = onChange;
            container.appendChild(slider);

            controlPanel.appendChild(container);
            return slider;
        };

        let brightness = 100, contrast = 100, saturation = 100;

        const updateFilters = () => {
            document.body.style.filter = `brightness(${brightness}%) contrast(${contrast}%) saturate(${saturation}%)`;
        };

        createSlider('Brightness', brightness, 50, 150, 1, (e) => { brightness = e.target.value; updateFilters(); });
        createSlider('Contrast', contrast, 50, 150, 1, (e) => { contrast = e.target.value; updateFilters(); });
        createSlider('Saturation', saturation, 50, 150, 1, (e) => { saturation = e.target.value; updateFilters(); });

        updateFilters();
    });
})();