网页亮度调整

用这个脚本来调整你的网页亮度

  1. // ==UserScript==
  2. // @name 网页亮度调整
  3. // @name:en Webpage brightness adjustment
  4. // @namespace mscststs
  5. // @version 0.40
  6. // @description 用这个脚本来调整你的网页亮度
  7. // @description:en Use this script to adjust the brightness of your page
  8. // @require https://gf.qytechs.cn/scripts/373588-mscststs-eventbus/code/mscststs-EventBus.js?version=639557
  9. // @author mscststs
  10. // @include /.*/
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_addValueChangeListener
  14. // @grant GM_registerMenuCommand
  15. // @grant unsafeWindow
  16. // @license MIT License
  17. // @noframes
  18. // @contributionURL https://blve.mscststs.com/img/Pay.png
  19. // @contributionAmount 5
  20. // @compatible firefox 旧版FF兼容性未考证,火狐量子版完全兼容
  21. // @compatible chrome
  22. // @compatible opera
  23. // @compatible safari
  24. // @run-at document-body
  25. // ==/UserScript==
  26.  
  27. (function() {
  28. 'use strict';
  29. const Default_config={
  30. globalBrightness: 0.9,
  31. SingleConfigMap:{
  32. /* {
  33. [window.location.host] : 0.9,
  34. }*/
  35. }
  36. }
  37. function isCN(){
  38. let lang = navigator.language||navigator.userLanguage;//常规浏览器语言和IE浏览器
  39. if(lang.indexOf('zh')>=0){
  40. return true;
  41. }else{
  42. return false;
  43. }
  44. }
  45. const CN_wordsMap = {
  46. MenuCmd:"打开亮度调整菜单",
  47. settingsTitle:"亮度调整",
  48. setAsDefault:"设为默认亮度",
  49. closeSettingWindow:"关闭设置窗口",
  50. DeafultSetText:"网页默认亮度已被设置为",
  51. }
  52. const EN_wordsMap = {
  53. MenuCmd:"Brightness adjustment menu",
  54. settingsTitle:"Brightness adjustment",
  55. setAsDefault:"Set As Default Brightness",
  56. closeSettingWindow:"Close the settings window",
  57. DeafultSetText:"The default brightness has been set to "
  58. }
  59. const wordsMap = isCN()?CN_wordsMap:EN_wordsMap;
  60. const body = document.querySelector("body");
  61.  
  62. let gm = new class{
  63. constructor(){
  64. this.key = "mscststs-brightness";
  65. this.init();
  66. }
  67. init(){
  68. GM_registerMenuCommand(wordsMap.MenuCmd,()=>{
  69. eve.emit("Cmd-OpenMenu");
  70. });
  71. GM_addValueChangeListener(this.key,(name, old_value, new_value, remote)=>{
  72. eve.emit("SettingUpdated",new_value);
  73. });
  74. }
  75. getNowBrightness(){
  76. let config = this.getConfig();
  77. return config.SingleConfigMap[window.location.host] || config.globalBrightness;
  78. }
  79. getConfig(){
  80. //读取配置文件
  81. return GM_getValue(this.key,Default_config);
  82. }
  83. setConfig(value){
  84. GM_setValue(this.key,value);
  85. }
  86. setGlobalBrightness(value){
  87. let config = this.getConfig();
  88. config.globalBrightness = value;
  89. this.setConfig(config);
  90. }
  91. setHostBrightness(value,host = window.location.host){
  92. let config = this.getConfig();
  93. config.SingleConfigMap[host] = value;
  94. this.setConfig(config);
  95. }
  96. }();
  97. function OpenMenuPage(){
  98. if(document.querySelector("#helper_brightness")){
  99. //当前Menu已存在
  100. }else{
  101. //Menu不存在,需要打开Menu
  102. let div = document.createElement("div");
  103. div.id = "helper_brightness";
  104. div.innerHTML = `
  105.  
  106. <div class="brightness-title">
  107. `+wordsMap.settingsTitle+`
  108. </div>
  109. <div class="brightness-Menu">
  110.  
  111. <div class="single">
  112. <div class="controller">
  113. <input id="helper_brightness_range" type="range" min="0" max="1" step="0.01" value="`+gm.getNowBrightness()+`"/>
  114. </div>
  115. <div class="desc">
  116. <div id="brightness-value">
  117. `+gm.getNowBrightness()+`
  118. </div>
  119. <div>
  120. <button id="helper_brightness_setAsDefault">
  121. `+wordsMap.setAsDefault+`
  122. </button>
  123. </div>
  124. <div>
  125. <button id="helper_brightness_closeSettingPage">
  126. `+wordsMap.closeSettingWindow+`
  127. </button>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132.  
  133. <style>
  134. #helper_brightness{
  135. position:fixed;
  136. color:black !important;
  137. display:block;
  138. left:calc( 50% - 210px);
  139. top:10%;
  140. border:1px solid #aaa;
  141. min-height:300px;
  142. width:400px;
  143. border-radius:8px;
  144. box-shadow:0 0 15px 0 #999;
  145. background-color:#eee;
  146. padding:10px;
  147. user-select:none;
  148. z-index:1000000; //100w
  149. }
  150. .brightness-title{
  151. color:black !important;
  152. text-align:center;
  153. border-bottom:1px solid #ccc;
  154. font-size:1.7em;
  155. line-height:2.5em;
  156. }
  157. #helper_brightness input[type=range] {
  158. background-color:rgb(221, 221, 221);
  159. -webkit-appearance: none;
  160. width: 300px;
  161. border-radius: 10px; /*这个属性设置使填充进度条时的图形为圆角*/
  162. }
  163. #helper_brightness input[type=range]::-webkit-slider-thumb {
  164. -webkit-appearance: none;
  165. }
  166.  
  167. #helper_brightness input[type=range]::-webkit-slider-runnable-track {
  168. height: 15px;
  169. border-radius: 10px; /*将轨道设为圆角的*/
  170. box-shadow: 0 1px 1px #def3f8, inset 0 .125em .125em #0d1112; /*轨道内置阴影效果*/
  171. }
  172.  
  173. #helper_brightness input[type=range]:focus {
  174. outline: none;
  175. }
  176.  
  177. #helper_brightness input[type="range"]::-webkit-slider-thumb{
  178. width:25px;
  179. -webkit-appearance: none;
  180. height: 25px;
  181. margin-top: -5px; /*使滑块超出轨道部分的偏移量相等*/
  182. background: #ffffff;
  183. border-radius: 50%; /*外观设置为圆形*/
  184. border: solid 0.125em rgba(205, 224, 230, 0.5); /*设置边框*/
  185. box-shadow: 0 .125em .125em #3b4547; /*添加底部阴影*/
  186.  
  187. }
  188.  
  189. #helper_brightness .brightness-Menu{
  190. margin-top:25px;
  191. }
  192. #helper_brightness .controller{
  193. padding:5px 0;
  194. margin:0 auto;
  195. width:300px;
  196. }
  197. #helper_brightness .desc{
  198. text-align:center;
  199. line-height:35px;
  200. }
  201. #helper_brightness button{
  202. background-color:#eee;
  203. font-size:14px;
  204. line-height:30px;
  205. border: 1px #bebebe solid;
  206. height: 30px;
  207. padding-left: 5px;
  208. padding-right: 5px;
  209. }
  210. #helper_brightness button:hover{
  211.  
  212. border: 1px #999 solid;
  213. }
  214.  
  215. #brightness-value{
  216. font-size:2.6em;
  217. height:60px;
  218. line-height:60px;
  219. color:black !important;
  220. }
  221.  
  222. </style>
  223.  
  224.  
  225. `
  226. body.appendChild(div);
  227. let rangeController = document.querySelector("#helper_brightness_range");
  228. let setAsDefaultBtn = document.querySelector("#helper_brightness_setAsDefault");
  229. let closeSettingPage = document.querySelector("#helper_brightness_closeSettingPage");
  230. let brightnessValue = document.querySelector("#brightness-value");
  231.  
  232. rangeController.addEventListener("input",(e)=>{
  233. let value = e.target.value;
  234. brightnessValue.innerText = value;
  235. gm.setHostBrightness(value);
  236. })
  237. setAsDefaultBtn.addEventListener("click",(e)=>{
  238. //设为默认亮度
  239. let value = rangeController.value;
  240.  
  241. gm.setGlobalBrightness(value);
  242. alert(wordsMap.DeafultSetText+value+"!");
  243. })
  244. closeSettingPage.addEventListener("click",(e)=>{
  245. CloseMenuPage();
  246. })
  247.  
  248. }
  249. }
  250. function CloseMenuPage(){
  251. let menu = document.querySelector("#helper_brightness");
  252. if(menu){
  253. menu.remove();
  254. }
  255. }
  256. eve.on("Cmd-OpenMenu",()=>{
  257. OpenMenuPage();
  258. })
  259. eve.on("SettingUpdated",()=>{
  260. Init();
  261. })
  262.  
  263. let CurrentBrightness = null;
  264. //插入style节点
  265. let styleNode = document.createElement("style")
  266. document.querySelector("head").append(styleNode)
  267. function Init(){
  268. if(CurrentBrightness && CurrentBrightness == gm.getNowBrightness()){
  269. //默认亮度未改变
  270. }else{
  271. CurrentBrightness = gm.getNowBrightness();
  272. }
  273. styleNode.innerHTML = `
  274.  
  275. body::after{
  276. content:"";
  277. display:block;
  278. background-color:#000;
  279. opacity:`+parseFloat(1-CurrentBrightness).toFixed(2)+`;
  280.  
  281. position:fixed;
  282. left:0;
  283. top:0;
  284. z-index:999999;
  285. width:100%;
  286. height:100%;
  287. pointer-events: none;
  288. }
  289.  
  290. `;
  291. }
  292. Init();
  293. //优化逻辑判断
  294. body.addEventListener("dblclick",(e)=>{
  295. if(e.ctrlKey){
  296. eve.emit("Cmd-OpenMenu")
  297. }
  298. })
  299. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址