// ==UserScript== // @name 网页亮度调整 // @namespace mscststs // @version 0.2 // @description 用这个脚本来调整你的网页亮度 // @require https://greasyfork.org/scripts/373588-mscststs-eventbus/code/mscststs-EventBus.js?version=639557 // @author mscststs // @include /.*/ // @grant GM_setValue // @grant GM_getValue // @grant GM_addValueChangeListener // @grant GM_registerMenuCommand // @grant unsafeWindow // @noframes // @run-at document-end // @downloadURL none // ==/UserScript== (function() { 'use strict'; const Default_config={ globalBrightness: 0.9, SingleConfigMap:{ /* { [window.location.host] : 0.9, }*/ } } const body = document.querySelector("body"); let gm = new class{ constructor(){ this.key = "mscststs-brightness"; this.init(); } init(){ GM_registerMenuCommand("打开亮度调整菜单",()=>{ eve.emit("Cmd-OpenMenu"); }); GM_addValueChangeListener(this.key,(name, old_value, new_value, remote)=>{ eve.emit("SettingUpdated",new_value); }); } getNowBrightness(){ let config = this.getConfig(); return config.SingleConfigMap[window.location.host] || config.globalBrightness; } getConfig(){ //读取配置文件 return GM_getValue(this.key,Default_config); } setConfig(value){ GM_setValue(this.key,value); } setGlobalBrightness(value){ let config = this.getConfig(); config.globalBrightness = value; this.setConfig(config); } setHostBrightness(value,host = window.location.host){ let config = this.getConfig(); config.SingleConfigMap[host] = value; this.setConfig(config); } }(); function OpenMenuPage(){ if(document.querySelector("#helper_brightness")){ //当前Menu已存在 }else{ //Menu不存在,需要打开Menu let div = document.createElement("div"); div.id = "helper_brightness"; div.innerHTML = `