1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
(function () { 'use strict'; if (self != top) { return false; } else { var eve = new class { constructor() { this.handles = {} }
on(event, callback, index = 0) { if (!this.handles[event]) { this.handles[event] = [] } this.handles[event].push({ callback: callback, index: index }); this.handles[event].sort((a, b) => { return b.index - a.index }) }
emit(event, ...data) { if (this.handles[event]) { for (let i of this.handles[event]) { if (i.callback(...data) === false) break } } }
off(event, callback, index = 0) { if (this.handles[event]) { let s = []; for (let i of this.handles[event]) { if (i.callback != callback && i.index != index) { s.push(i) } } this.handles[event] = s } } }(); const Default_config = { globalBrightness: 0.95, SingleConfigMap: {} }; const wordsMap = { MenuCmd: "打开亮度调整菜单", settingsTitle: "亮度调整", setAsDefault: "设为默认亮度", closeSettingWindow: "关闭设置窗口", DeafultSetText: "网页默认亮度已被设置为", }; const body = document.querySelector("body"); let gm = new class { constructor() { this.key = "mscststs-brightness"; this.init() }
init() { GM_registerMenuCommand(wordsMap.MenuCmd, () => { 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")) { } else { let div = document.createElement("div"); div.id = "helper_brightness"; div.innerHTML = '<div class="brightness-title">' + wordsMap.settingsTitle + '</div><div class="brightness-Menu"><div class="single"><div class="controller"><input id="helper_brightness_range" type="range" min="0" max="1" step="0.01" value="' + gm.getNowBrightness() + '"/></div><div class="desc"><div id="brightness-value">' + gm.getNowBrightness() + '</div><div><button id="helper_brightness_setAsDefault">' + wordsMap.setAsDefault + '</button></div><div><button id="helper_brightness_closeSettingPage">' + wordsMap.closeSettingWindow + '</button></div></div></div></div><style>#helper_brightness{position:fixed;color:black!important;display:block;left:calc(50% - 210px);top:10%;border:1px solid #aaa;min-height:300px;width:400px;border-radius:8px;box-shadow:0 0 15px 0 #999;background-color:#eee;padding:10px;user-select:none;z-index:1000000;//100w}.brightness-title{color:black!important;text-align:center;border-bottom:1px solid #ccc;font-size:1.7em;line-height:2.5em}#helper_brightness input[type=range]{background-color:#ddd;-webkit-appearance:none;width:300px;border-radius:10px}#helper_brightness input[type=range]::-webkit-slider-thumb{-webkit-appearance:none}#helper_brightness input[type=range]::-webkit-slider-runnable-track{height:15px;border-radius:10px;box-shadow:0 1px 1px #def3f8,inset 0 .125em .125em #0d1112}#helper_brightness input[type=range]:focus{outline:0}#helper_brightness input[type="range"]::-webkit-slider-thumb{width:25px;-webkit-appearance:none;height:25px;margin-top:-5px;background:#fff;border-radius:50%;border:solid .125em rgba(205,224,230,0.5);box-shadow:0 .125em .125em #3b4547}#helper_brightness .brightness-Menu{margin-top:25px}#helper_brightness .controller{padding:5px 0;margin:0 auto;width:300px}#helper_brightness .desc{text-align:center;line-height:35px}#helper_brightness button{background-color:#eee;font-size:14px;line-height:30px;border:1px #bebebe solid;height:30px;padding-left:5px;padding-right:5px}#helper_brightness button:hover{border:1px #999 solid}#brightness-value{font-size:2.6em;height:60px;line-height:60px;color:black!important}</style>' body.appendChild(div); let rangeController = document.querySelector("#helper_brightness_range"); let setAsDefaultBtn = document.querySelector("#helper_brightness_setAsDefault"); let closeSettingPage = document.querySelector("#helper_brightness_closeSettingPage"); let brightnessValue = document.querySelector("#brightness-value"); rangeController.addEventListener("input", (e) => { let value = e.target.value; brightnessValue.innerText = value; gm.setHostBrightness(value); }); setAsDefaultBtn.addEventListener("click", (e) => { let value = rangeController.value; gm.setGlobalBrightness(value); alert(wordsMap.DeafultSetText + value + "!"); }); closeSettingPage.addEventListener("click", (e) => { CloseMenuPage(); }) } };
function CloseMenuPage() { let menu = document.querySelector("#helper_brightness"); if (menu) { menu.remove(); } }
eve.on("Cmd-OpenMenu", () => { OpenMenuPage(); }); eve.on("SettingUpdated", () => { Init(); }); let CurrentBrightness = null; let styleNode = document.createElement("style"); document.querySelector("head").append(styleNode);
function Init() { if (CurrentBrightness && CurrentBrightness == gm.getNowBrightness()) { } else { CurrentBrightness = gm.getNowBrightness(); } styleNode.innerHTML = 'body::after{source:"";display:block;background-color:#000;opacity:' + parseFloat(1 - CurrentBrightness).toFixed(2) + ';position:fixed;left:0;top:0;z-index:999999;width:100%;height:100%;pointer-events:none;}'; }; Init(); body.addEventListener("dblclick", (e) => { if (e.ctrlKey) { eve.emit("Cmd-OpenMenu"); } }) } })();
|