本站不兼容 8 以前的版本的 Interner Explorer 浏览器(或基于这些版本的 IE 的其他浏览器),并且页面样式不完全兼容 IE 8,我们建议你升级至 IE 9 或改用其他非 IE 浏览器

Mozest™

  • 正在加载用户菜单…

开放、分享、互助

转播到腾讯微博
返回列表 回复 发帖

GM脚本Nightingale View

本帖最后由 凯杰 于 2009-2-19 17:47 编辑
  1. // ==UserScript==
  2. // @name           Nightingale View
  3. // @namespace      com.mozest.keijack
  4. // @auther                Keijack
  5. // @version        1.0.1
  6. // @description    减低页面的亮度, 在黑暗中查看页面有助于保护眼镜(?)
  7. // @include        *
  8. // ==/UserScript==
  9. /**
  10. * 以下是默认配置修改
  11. */
  12. var showCoverDefault = true; //  true 为默认打开遮罩, false为默认不打开
  13. var coverOpacity = 0.50; // 默认暗度
  14. var link = true; // 为true, 会把所有的文字链接置到遮罩前方(可以点击文字链接), false 相反

  15. /**
  16. * 以下是实现代码
  17. */
  18. // 变量的定义
  19. var cover = null; // 底层遮盖
  20. var created = false; // 是否已经建立遮盖
  21. var show = false;

  22. // 遮盖显示方法
  23. function showCover(){
  24.         if(!created){
  25.                 cover = document.createElement('div');
  26.                 cover.setAttribute('style', 'background: black; width: 100%; height: 100%; position: fixed; left: 0; bottom: 0; overflow: hidden; z-index: 100;');
  27.                 cover.style.opacity = new String(coverOpacity);
  28.                 document.body.appendChild(cover);
  29.                 // 链接的处理
  30.                 if(link){
  31.                         var as = document.getElementsByTagName('a');
  32.                         for(var i = 0; i < as.length; i++){
  33.                                 // 只处理文字链接
  34.                                 var aimgs = as.getElementsByTagName('img');
  35.                                 if(aimgs.length == 0 ){
  36.                                         as.style.position = 'relative';
  37.                                         as.style.zIndex = '101';
  38.                                 }
  39.                         }
  40.                 }
  41.                 // 标识已创建
  42.                 created = true;
  43.         } else {
  44.                 cover.style.display = '';
  45.         }
  46.         show = true;
  47. }

  48. // 遮盖的隐藏
  49. function hideCover(){
  50.         if(!created){
  51.                 return;
  52.         }
  53.         cover.style.display = 'none';
  54.         show = false;
  55. }

  56. // 增加事件处理
  57. window.addEventListener('keydown', function(e){
  58.         if(e.altKey && e.keyCode == 116){ // alt + F5, 打开/关闭遮罩
  59.                 if(!show)
  60.                         showCover();
  61.                 else
  62.                         hideCover();
  63.         } else if(e.altKey && e.keyCode == 38){ // alt + UP, 暗度升高
  64.                 if(!created){
  65.                         return;
  66.                 }
  67.                 if(cover.style.opacity >= 1){
  68.                         return;
  69.                 }
  70.                 var opacity = new Number(cover.style.opacity);
  71.                 opacity += 0.05;
  72.                 cover.style.opacity = new String(opacity);
  73.         } else if(e.altKey && e.keyCode == 40){ // alt + DOWN, 暗度降低
  74.                 if(!created){
  75.                         return;
  76.                 }
  77.                 if(cover.style.opacity <=0){
  78.                         return;
  79.                 }
  80.                 var opacity = new Number(cover.style.opacity);
  81.                 opacity -= 0.05;
  82.                 cover.style.opacity = new String(opacity);
  83.         } else if(e.altKey && e.keyCode == 117){ // alt + F6, 默认暗度
  84.                 if(!created){
  85.                         return;
  86.                 }
  87.                 cover.style.opacity = new String(coverOpacity);
  88.         }
  89. }, true);

  90. // 默认打开遮罩
  91. if(showCoverDefault){
  92.         showCover();
  93. }
复制代码
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.

沙发,鼓掌支持!
还是想问下,能不能修改成UC.js脚本。
沙发,鼓掌支持!
还是想问下,能不能修改成UC.js脚本。
hocoo 发表于 2009-2-18 12:02
如果楼上不想装GM扩展,请看http://g.mozest.com/thread-27616-1-1,复制脚本到content 目录内
多谢版主,脚本不错,只是Alt + F5 可打开,不可关闭,再按变成了提高 NV 的暗度
Alt + F6 将 NV 的暗度置为默认的暗度无效
Alt + ↑ 提高 NV 的暗度无效
Alt + ↓ 减低 NV 的暗度无效
望修成
多谢版主,脚本不错,只是Alt + F5 可打开,不可关闭,再按变成了提高 NV 的暗度
Alt + F6 将 NV 的暗度置为默认的暗度无效
Alt + ↑ 提高 NV 的暗度无效
Alt + ↓ 减低 NV 的暗度无效
望修成 ...
zerofme 发表于 2009-2-18 13:37
脚本用GM扩展运行也一样
我也是用GM扩展出现的状况,而且链接无法点击
页面上所有链接无效...

FF firefox-3.2a1最新版
没事就喜欢瞎折腾Firefox
本帖最后由 凯杰 于 2009-2-18 16:40 编辑

5# qjahz

我在想是不是有其他脚本的快捷键冲突了呢? 能只开一个脚本试试?
同时, 想问一下, 用的是笔记本电脑? 键盘类型?
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.

5# qjahz

我在想是不是有其他脚本的快捷键冲突了呢? 能只开一个脚本试试?
同时, 想问一下, 用的是笔记本电脑? 键盘类型?
凯杰 发表于 2009-2-18 16:32
1.只运行
Nightingale View,只有alt+f6和firefox自带快捷键冲突。所有功能无效。
多谢版主,脚本不错,只是Alt + F5 可打开,不可关闭,再按变成了提高 NV 的暗度
Alt + F6 将 NV 的暗度置为默认的暗度无效
Alt + ↑ 提高 NV 的暗度无效
Alt + ↓ 减低 NV 的暗度无效
望修成 ...
zerofme 发表于 2009-2-18 13:37
状况一样
Alt + F5我开不了啊
本帖最后由 cwzh_115 于 2009-2-19 00:45 编辑

谢谢凯杰~

望改进,楼上的说法在我的笔记本上一 一得到证实
12# cwzh_115

笔记本的键盘估计的 按键码 估计有不同, 惨在现在手头上没有笔记本, 难以测试, 我想想解决方法...
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.

所有链接无效,这是最大的问题。3.06版的
14# chaosmsn
文字链接应该没有问题, 除非链接中包含图片, 不把图片链接放出来是因为图片链接会变亮...
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.

确实所有链接都被遮蔽。仅启用这一个脚本也无法解决。
14# chaosmsn
文字链接应该没有问题, 除非链接中包含图片, 不把图片链接放出来是因为图片链接会变亮...
凯杰 发表于 2009-2-19 09:31
论坛里的引用 回复这些链接都不行
17# littleboyzt

呃...我在3.0测试下是有效的...要看看 3.1 和 3.2 的版本...
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.

17# littleboyzt

呃...我在3.0测试下是有效的...要看看 3.1 和 3.2 的版本...
凯杰 发表于 2009-2-19 16:51
使用的是3.06,油猴版本为1月23日版,使用此脚本后所有链接一律不可点击,仅加载此脚本依旧问题。且安装此脚本时安装说明为乱码。难不成是因为用的笔记本么?
19# jpsdwang

呃...用 utf8 的编码保存试一下?
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.

额,在3.06下试用报告:
1
一开始默认打开的,开了几个页面都能有效(指有遮蔽效果,亮度调整,开关,链接也能打开,但有的网站滚轮无效,比如greader。

2
修改脚本为遮蔽效果默认关闭,仅修改此项。再打开几个新页面,则无效(打不开)。但在未修改脚本钱打开的页面上仍部分有效(本论坛上链接无效,但校内上有效)。

3
改回默认遮蔽效果打开,全部无效。
在firefox-3.2a1pre.en-US.win32下试用报告:除页面超链接有效外,其他点击无效,如图片链接,点击图片右键图片地址,
PS:在本论坛不能正常点击回复框回复.....
没事就喜欢瞎折腾Firefox
18# 凯杰
我的是3.05
3.1 beta 2 试用报告,一切正常,很正 。但给一个建议:就是遮罩与链接的边缘留一点,这样可以显原来的背景颜色,链接会更清楚可见。不知可否办到
补充:图片链接如上有点问题
嗯, 先说一下工作原理, 这个脚本的工作原理是建立一个整个黑色背景, 半透明的遮罩, 然后覆盖页面以降低页面的亮度的. 也就是说, 在这种情况下, 原来页面的所有的东西都在遮盖之下, 所以, 原来的页面元素的所有动作, 都会被遮挡. 如果要使元素的动作有效就必须让元素在遮罩的上面, 这样一来, 元素就会恢复原本的亮度, 遮盖也就失去了意义. 所以在处理链接的时候, 因为文字的颜色会相对不太光亮, 所以只将文字链接放到遮盖上面, 所以, 图片/输入框/按钮等都放在了遮盖的下面, 而无法对其进行操作.
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.

手都按酸了也没用,笔记本
凯杰,即使更新到1.0.1后,我的快捷键ALT+F6一样没有作用,再就是我按ALT+F5结果成亮度变暗了~
经测试附件中的脚本有效果且正常,但页面中的代码就会出现问题!
图片链接无效了,其他正常
另外最大的问题是:论坛根本没法回帖啊