如何用chrome扩展将网页变成黑底白字,用以保护视力

不知道有没有科学依据,自己感觉黑底白字对视力好些,于是动手加个chrome扩展:

第一步:建个文件夹,名称比如叫changeColor;

第二步:在changeColor文件夹中建三个文件:manifest.json  、  background.js   和 content_script.js

第三步:编辑三个文件 

manifest.json放入以下代码 

{"name": "Page color","description": "Make the current page color","version": "2.0","permissions": ["activeTab"],"background": {"scripts": ["background.js"],"persistent": false},"browser_action": {"default_title": "change color"},"manifest_version": 2
}

background.js的代码

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {// No tabs or host permissions needed!console.log('Turning ' + tab.url + ' red!');chrome.tabs.executeScript(null, {file: "content_script.js"});
});

content_script.js代码

document.body.style.backgroundColor="black";
document.body.style.color="white";
var myP = document.getElementsByTagName("p"); 
for (var i=0;i<myP.length;i++)
{myP[i].style.backgroundColor = "black"; myP[i].style.color = "white"; };
var myDiv = document.getElementsByTagName("div");
for (var i=0;i<myDiv.length;i++)
{myDiv[i].style.backgroundColor = "black"; myDiv[i].style.color = "white"; };
var myBlockquote = document.getElementsByTagName("blockquote");
for (var i=0;i<myBlockquote.length;i++)
{myBlockquote[i].style.background = "grey"; myBlockquote[i].style.color = "white"; };
var myA = document.getElementsByTagName("a");
for (var i=0;i<myA.length;i++)
{   myA[i].style.color = "white"; };
var myul = document.getElementsByTagName("ul");
for (var i=0;i<myul.length;i++)
{myul[i].style.background = "black"; myul[i].style.color = "white"; };
var myli = document.getElementsByTagName("li");
for (var i=0;i<myli.length;i++)
{myli[i].style.background = "black"; myli[i].style.color = "white"; };
var myspan = document.getElementsByTagName("span");
for (var i=0;i<myspan.length;i++)
{myspan[i].style.background = "black"; myspan[i].style.color = "white"; };
var mypre = document.getElementsByTagName("pre");
for (var i=0;i<mypre.length;i++)
{mypre[i].style.background = "black"; mypre[i].style.color = "white"; };
var mysection = document.getElementsByTagName("section");
for (var i=0;i<mysection.length;i++)
{mysection[i].style.background = "black"; mysection[i].style.color = "white"; };
var mytable = document.getElementsByTagName("table");
for (var i=0;i<mytable.length;i++)
{mytable[i].style.background = "black"; mytable[i].style.color = "white"; };

第四步 打开chrome浏览器,在地址栏输入chrome://extensions    或者 点最右边三个点-更多工具-扩展程序

第五步  钩选 开发者模式 ,从资源管理器将changeColor文件夹拖放到扩展程序页面上 或者 点加载已解压的扩展程序也可。

第六步 在新标签中打开某个网页,比如:baidu.com  ,再点地址栏右边扩展图标,页面文字变成黑底白字了。

补充:在打开某个页面时,发现还有白块,于是在白块上点鼠标右键,再点 检查,在页面代码中发现是 th 和footer 的背景,于是在content_script.js的最后加以上以代码

var myth = document.getElementsByTagName("th");
for (var i=0;i<myth.length;i++)
{myth[i].style.background = "black"; myth[i].style.color = "white"; };
var footer = document.getElementsByTagName("footer");
for (var i=0;i<footer.length;i++)
{footer[i].style.background = "black"; footer[i].style.color = "white"; };

然后在chrome扩展页面按下 ctrl-R  ,之后在有白块的页面上点击地址栏右侧的扩展图标。嗯,找到了上学时看黑板的感觉了。

后记,使用时发现还会有个别块背景不是黑色,

干脆将content_script.js中全部内容用以下代码替换

var all = document.getElementsByTagName("*");
for (var i=0;i<all.length;i++)
{all[i].style.background = "black"; all[i].style.color = "white"; };
不过由于选择元素太多 ,感觉脚本执行速度慢了。另外在360浏览器下需加上图标,否则需钩选 【插件栏显示扩展名称】才能看到自己的扩展。

 

转载于:https://www.cnblogs.com/pu369/p/6381560.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393927.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

从零学习机器学习_机器学习:如何从零变英雄

从零学习机器学习以“为什么&#xff1f;”开头 并以“我准备好了&#xff01;”结尾 (Start with “Why?” and end with “I’m ready!”) If your understanding of A.I. and Machine Learning is a big question mark, then this is the blog post for you. Here, I gradu…

sqoop动态分区导入mysql,使用sqoop import从mysql往hive含分区表中导入数据的一些注意事项...

先看下面这条语句&#xff0c;它实现的功能是将特定日期的数据从mysql表中直接导入hive$ sqoop import \--connect jdbc:mysql://192.168.xx.xx:3306/db_name?useSSLfalse \--username xxx --password xxxxxx \--query "select d.id, d.callsign, d.sobt from t_flight_b…

leetcode面试题 08.04. 幂集(递归)

幂集。编写一种方法&#xff0c;返回某集合的所有子集。集合中不包含重复的元素。 说明&#xff1a;解集不能包含重复的子集。 示例: 输入&#xff1a; nums [1,2,3] 输出&#xff1a; [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 代码 class Solution {List&l…

gatsby_我如何使用Gatsby和Netlify建立博客

gatsbyby Pav Sidhu通过帕夫西杜(Pav Sidhu) 我如何使用Gatsby和Netlify建立博客 (How I Built My Blog Using Gatsby and Netlify) 您能说出更具标志性的二人​​组合吗&#xff1f; &#xff1f; (Can you name a more iconic duo? ?) Years ago, whenever I built a stat…

交叉熵与相对熵

熵的本质是香农信息量()的期望。 现有关于样本集的2个概率分布p和q&#xff0c;其中p为真实分布&#xff0c;q非真实分布。 按照真实分布p来衡量识别一个样本的所需要的编码长度的期望(即平均编码长度)为&#xff1a;H(p)。 如果使用错误分布q来表示来自真实分布p的平均编码长度…

menustrip

在对应菜单上点击鼠标右键&#xff0c;插入&#xff0c;SEPARATOR 就可以了&#xff0c;然后可以选中拖动位置。转载于:https://www.cnblogs.com/Echo529/p/6382302.html

直接排序

题目&#xff1a;使用直接排序法将下列数组&#xff08;从小到大排序&#xff09;思路&#xff1a;第一次&#xff1a;使用索引值为0的元素与其他位置的元素挨个比较一次&#xff0c;如果发现比0号索引值的元素小的&#xff0c;那么交换位置&#xff0c;第一轮下来最小值被放在…

leetcode78. 子集(回溯)

给定一组不含重复元素的整数数组 nums&#xff0c;返回该数组所有可能的子集&#xff08;幂集&#xff09;。 说明&#xff1a;解集不能包含重复的子集。 示例: 输入: nums [1,2,3] 输出: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 代码 class Solution {pub…

php字符串综合作业,0418php字符串的操作

实例字符串函数(一):长度计算$siteName php中文网;//获取内部字符编码集$encoding mb_internal_encoding();//1、strlen($str):获取字节表示的字符串长度//utf8模式下&#xff0c;一个中文字符用三个字节表示echo strlen($siteName),; //12//2、mb_strlen($str,$encoding)&…

如何处理JavaScript中的事件处理(示例和全部)

In this blog, I will try to make clear the fundamentals of the event handling mechanism in JavaScript, without the help of any external library like Jquery/React/Vue.在此博客中&#xff0c;我将尝试在没有任何外部库(例如Jquery / React / Vue)的帮助下阐明JavaSc…

js 图片预览

//显示选择的图片缩略图function showImage(inputId,imageConfirmId,imageConfi){var imagedocument.getElementById(inputId).value.toLowerCase();if(!image){return;}var fileExtendimage.substr(image.lastIndexOf(".", image.length)1);if(!(fileExtend"jp…

什么是copyonwrite容器

2019独角兽企业重金招聘Python工程师标准>>> CopyOnWrite容器即写时复制的容器。通俗的理解是当往一个容器添加元素的时候&#xff0c;不直接往当前容器添加&#xff0c;而是先将当前容器进行Copy&#xff0c;复制出一个新的容器&#xff0c;然后新的容器里添加元素…

hystrix 源码 线程池隔离_Hystrix源码学习--线程池隔离

分析你的系统你所认识的分布式系统&#xff0c;哪些是可以进行垂直拆分的&#xff1f;拆分之后系统之间的依赖如何梳理&#xff1f;系统异构之后的稳定性调用如何保证&#xff1f;这些都是可能在分布式场景中面临的问题。说个比较常见的问题&#xff0c;大家都知道秒杀系统&…

P2341 [HAOI2006]受欢迎的牛 强连通

题目背景 本题测试数据已修复。 题目描述 每头奶牛都梦想成为牛棚里的明星。被所有奶牛喜欢的奶牛就是一头明星奶牛。所有奶 牛都是自恋狂&#xff0c;每头奶牛总是喜欢自己的。奶牛之间的“喜欢”是可以传递的——如果A喜 欢B&#xff0c;B喜欢C&#xff0c;那么A也喜欢C。牛栏…

oracle em agent,ORACLE 11G EM 配置命令及问题处理

11g装好以后&#xff0c;一直未用EM,昨天晚上和今天晚上终于抽时间把EM启动起来了&#xff0c;还遇到一点小问题&#xff0c;1.EM配置的一些命令创建一个EM资料库emca -repos create重建一个EM资料库emca -reposrecreate--------这个很主要&#xff0c;一般第一次不成功创建的时…

leetcode89. 格雷编码

格雷编码是一个二进制数字系统&#xff0c;在该系统中&#xff0c;两个连续的数值仅有一个位数的差异。 给定一个代表编码总位数的非负整数 n&#xff0c;打印其格雷编码序列。即使有多个不同答案&#xff0c;你也只需要返回其中一种。 格雷编码序列必须以 0 开头。 示例 1:…

注重代码效率_如何提升质量:注重态度

注重代码效率by Harshdeep S Jawanda通过Harshdeep S Jawanda 如何提升质量&#xff1a;注重态度 (How to skyrocket quality: focus on attitude) When it comes to discussing quality and how we can improve, the most common things that come to peoples minds are test…

spark mllib推荐算法使用

2019独角兽企业重金招聘Python工程师标准>>> 一、pom.xml <!-- 机器学习包 --><dependency><groupId>org.apache.spark</groupId><artifactId>spark-mllib_2.10</artifactId><version>${spark.version}</version>&…

Android仿QQ复制昵称效果2

本文同步自http://javaexception.com/archives/77 背景: 在上一篇文章中&#xff0c;给出了一种复制QQ效果的方案&#xff0c;今天就来讲讲换一种方式实现。主要依赖的是一个开源项目https://github.com/shangmingchao/PopupList。 解决办法: PopupList.java的代码封装的比较完…

R语言的自定义函数—字符组合

前两天写了几个函数&#xff0c;对里面收获到的一些东西做一些记录。 函数str_comb&#xff0c;用于输入一个字符串或数值向量&#xff0c;返回由向量中元素组成的不重复的长度小于向量长度的所有组合&#xff0c;结果用矩阵形式输出。 函数使用结果如下&#xff1a; 思路很简单…