alexfire
小狐狸
小狐狸
  • UID33196
  • 注册日期2010-06-28
  • 最后登录2019-03-03
  • 发帖数32
  • 经验28枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1192回复:0

求修改 F2改变网页背景色 的脚本,能增加修改字体大小的么?

楼主#
更多 发布于:2011-11-18 13:06
// ==UserScript==
// @author         Ben Lee
// @name           F2改变网页背景色
// @description    Changes color of page to grey text on black background to make pages easier to read.  Uses F2 to toggle colors on and off.
// @namespace      http://www.benslee.com/
// @include        *
// ==/UserScript==

/*
	Notes:  This has not been thoroughly tested.   It was made to save my eyes.  I love reading nytimes.com, but after a while, my eyes start bugging out because of the white background.  I put togther this script with some code borrowed from various sites on the internet.  Unfortunately I don't remember the sites to properly credit those involved.

	Feb 22, 2008 - ver 1.1 - Added comments, cleaned up code, and eliminated js warning by switching to style instead of link tag.
	Feb 22, 2008 - ver 1.0 - Released into the wild.
*/

var teNewBackgroundColor, teNewTextColor, teNewLinkColor, teNewVisitedColor, teMyKeyCode;
var teNewStyle

//  Change any of these to values you think are more appropriate.
teNewBackgroundColor = '#dcecf5';  // Background replaced with this color.
teNewTextColor = '#000000';  // Text color changed to this color.
teNewLinkColor = '#1321CC';  // Link color changed to this color.
teNewVisitedColor = '#DDDDDD';  // Visited link color changed to this color.
teMyKeyCode = 113; //  keyCode 113 represents F2

// Create new style tag.
teNewStyle = document.createElement('style')
teNewStyle.id = 'teStylesheet';
teNewStyle.innerHTML = '* {background: ' + teNewBackgroundColor + ' !important; color: ' + teNewTextColor + ' !important} '
teNewStyle.innerHTML += ':link, :link * { color: ' + teNewLinkColor + ' !important}'
teNewStyle.innerHTML += ':visited, :visited *, { color: ' + teNewVisitedColor + ' !important};'

window.addEventListener('keypress', changeColors, true);

function changeColors(e) {
	var teNewStyleSheet, teOldStyleSheet, teStyles;

	if (e.keyCode == teMyKeyCode) {
		teOldStyleSheet = document.getElementById("teStylesheet")
		if (teOldStyleSheet){ // if oldStyleSheet already exists, it is removed.
			document.getElementsByTagName("head")[0].removeChild(teNewStyle );
		} else {  // if oldStyleSheet does not exist, it is created and added.
			document.getElementsByTagName("head")[0].appendChild(teNewStyle);
		}
	}
}
游客

返回顶部