|
|
顶楼
发表于 2009-2-18 11:56
| 只看该作者
GM脚本Nightingale View
本帖最后由 凯杰 于 2009-2-19 17:47 编辑 - // ==UserScript==
- // @name Nightingale View
- // @namespace com.mozest.keijack
- // @auther Keijack
- // @version 1.0.1
- // @description 减低页面的亮度, 在黑暗中查看页面有助于保护眼镜(?)
- // @include *
- // ==/UserScript==
- /**
- * 以下是默认配置修改
- */
- var showCoverDefault = true; // true 为默认打开遮罩, false为默认不打开
- var coverOpacity = 0.50; // 默认暗度
- var link = true; // 为true, 会把所有的文字链接置到遮罩前方(可以点击文字链接), false 相反
- /**
- * 以下是实现代码
- */
- // 变量的定义
- var cover = null; // 底层遮盖
- var created = false; // 是否已经建立遮盖
- var show = false;
- // 遮盖显示方法
- function showCover(){
- if(!created){
- cover = document.createElement('div');
- cover.setAttribute('style', 'background: black; width: 100%; height: 100%; position: fixed; left: 0; bottom: 0; overflow: hidden; z-index: 100;');
- cover.style.opacity = new String(coverOpacity);
- document.body.appendChild(cover);
- // 链接的处理
- if(link){
- var as = document.getElementsByTagName('a');
- for(var i = 0; i < as.length; i++){
- // 只处理文字链接
- var aimgs = as.getElementsByTagName('img');
- if(aimgs.length == 0 ){
- as.style.position = 'relative';
- as.style.zIndex = '101';
- }
- }
- }
- // 标识已创建
- created = true;
- } else {
- cover.style.display = '';
- }
- show = true;
- }
- // 遮盖的隐藏
- function hideCover(){
- if(!created){
- return;
- }
- cover.style.display = 'none';
- show = false;
- }
- // 增加事件处理
- window.addEventListener('keydown', function(e){
- if(e.altKey && e.keyCode == 116){ // alt + F5, 打开/关闭遮罩
- if(!show)
- showCover();
- else
- hideCover();
- } else if(e.altKey && e.keyCode == 38){ // alt + UP, 暗度升高
- if(!created){
- return;
- }
- if(cover.style.opacity >= 1){
- return;
- }
- var opacity = new Number(cover.style.opacity);
- opacity += 0.05;
- cover.style.opacity = new String(opacity);
- } else if(e.altKey && e.keyCode == 40){ // alt + DOWN, 暗度降低
- if(!created){
- return;
- }
- if(cover.style.opacity <=0){
- return;
- }
- var opacity = new Number(cover.style.opacity);
- opacity -= 0.05;
- cover.style.opacity = new String(opacity);
- } else if(e.altKey && e.keyCode == 117){ // alt + F6, 默认暗度
- if(!created){
- return;
- }
- cover.style.opacity = new String(coverOpacity);
- }
- }, true);
- // 默认打开遮罩
- if(showCoverDefault){
- showCover();
- }
复制代码 1. 概述
论坛上 cwzh_115 求写一个 Nightingale View 脚本, 主要是想降低页面的亮度, 这样在夜里看页面对眼镜的压力没那么大, 特别是在黑暗的情况下, 我不是医生, 不知道这样的功能是不是真的可以保护眼睛. 参考了一些代码之后, 写了相关的功能代码在回帖上, 之后有了许多其他的需求. 今天在整理了各部分的需求之后, 我重写了代码, 实现了默认打开和调整亮度的功能. 算是发布个正式版吧, 由于我个人不太使用这些功能, 所以自己想不到新的需求, 所以广大坛友如果有新的需求可以回帖说明, 如果有时间我会加上.
2. 版本说明
* 1.0.0 发布Nightingale View.
* 1.0.1 修正了在将透明度调为0之后, 无法用 Alt + F6 将暗度置为默认的BUG
3. 使用说明
1) 这个是GreaseMonkey的脚本, 如何安装使用GreaseMonkey及脚本请参考置顶帖.
2) 快捷键 Alt + F5 打开/关闭 NV.
Alt + F6 将 NV 的暗度置为默认的暗度
Alt + ↑ 提高 NV 的暗度
Alt + ↓ 减低 NV 的暗度
2) 在脚本中, 存在3个默认值可以修改.
showCoverDefault 表示是否默认打开, true 为默认打开, false 为默认关闭
coverOpacity 默认的暗度, 从 0~1 之间的浮点数.
link 将这项设为 true 会将文字链接放到遮盖前面, 可以点解链接, 设为 false 则相反.
4. 相关附件
|
附件: 您所在的用户组无法下载或查看附件
Welcome Humans!
We have come to visit you in peace and with goodwill!
* Robots may not injure a human being or, through inaction, allow a human being to come to harm.
* Robots have seen things you people wouldn't believe.
* Robots are Your Plastic Pal Who's Fun To Be With.
* Robots have shiny metal posteriors which should not be bitten.
And they have a plan. |
|