Jump to content

User:Ahecht/Scripts/ReadingMode.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if (typeof(readingBG) === "undefined") {var readingBG = "#f6f6f6";}

function toggleReadingMode(buttonElement) {
	var contentStyle = document.getElementById("content").style;
	if (contentStyle.backgroundColor == readingBG) {
		contentStyle.backgroundColor = "";
		buttonElement.alt= "Reading Mode";
		buttonElement.title= "Change to Reading Mode";
	} else {
		contentStyle.backgroundColor = readingBG;
		readingBG = contentStyle.backgroundColor; //handle IE color format change
		buttonElement.alt = "Normal Mode";
		buttonElement.title= "Change to Normal Mode";
	}
}

$(document).ready(function() {
	var rb=document.createElement("input");
	rb.type="image";
	rb.src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Eye_Icon.svg/20px-Eye_Icon.svg.png";
	rb.alt="Reading Mode";
	rb.title="Change to Reading Mode";
	rb.setAttribute( "onClick", "toggleReadingMode(this)" );
	var h=document.getElementById('firstHeading');
	h.insertBefore(rb,h.firstChild);
});