Colorful Glasses

改变网页背景颜色(Changing the background color of web)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Colorful Glasses
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  改变网页背景颜色(Changing the background color of web)
// @author       Zz
// @include      *
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

var canvas = document.createElement('canvas');
var r = GM_getValue('r', 0);
var g = GM_getValue('g', 0);
var b = GM_getValue('b', 0);
var a = GM_getValue('a', 0.1);

GM_registerMenuCommand("改变背景颜色", function(){
    var color = prompt("请输入RGB颜色值和透明度,中间用逗号隔开,例如绿豆沙色 199,238,206,0.5","");
    var colors = color.split(',');
    if (colors.length == 4) {
        r = colors[0];
        GM_setValue('r',r);
        g = colors[1];
        GM_setValue('g',g);
        b = colors[2];
        GM_setValue('b',b);
        a = colors[3];
        GM_setValue('a',a);
        canvas.getContext('2d').fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
        canvas.getContext('2d').clearRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
        canvas.getContext('2d').fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
    } else {
        alert("您输入的格式不对哦");
    }
});

GM_registerMenuCommand("默认背景颜色", function(){
    GM_setValue('r',0);
    GM_setValue('g',0);
    GM_setValue('b',0);
    GM_setValue('a',0.1);
    canvas.getContext('2d').fillStyle = 'rgba(0,0,0,0.1)';
    canvas.getContext('2d').clearRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
    canvas.getContext('2d').fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
});

canvas.style.position = 'fixed';
canvas.style.pointerEvents = 'none';
canvas.style.minWidth = '100%';
canvas.style.minHeight = '100%';
canvas.style.top = 0;
canvas.style.left = 0;
canvas.style.width = 'auto';
canvas.style.height = 'auto';
canvas.style.zIndex = 10000;
var context = canvas.getContext('2d');
context.fillStyle = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
context.fillRect(0, 0, document.body.offsetWidth, document.body.offsetHeight);
document.body.insertBefore(canvas, document.body.firstChild);