/**
 * Wikipedia Read Mode, inject.js
 * This script will be injected to the wikipedia page
 * And it will function as a wiki script rather than a content 
 * Script
 */


//==================================================================
// loading properties from localStorage
//================================================================== 

var ewprops = {
	enabled: true,
	font: "Calibri",
	size: 30
}

if (localStorage['ew_enabled'] 
	&& localStorage['ew_enabled'] == "false") {
	ewprops.enabled = false;
}
if (localStorage['ew_font']) {
	ewprops.font = localStorage['ew_font'];
}
if (localStorage['ew_size']) {
	ewprops.size = localStorage['ew_size'];
}

//==================================================================
// Methods that will be called by eventlisteners
//==================================================================

//function to refref the properties
function refreshProperty() {
	if (localStorage['ew_font']) {
		ewprops.font = localStorage['ew_font'];
	}
	if (localStorage['ew_size']) {
		ewprops.size = localStorage['ew_size'];
	}
}

//add a function to reset the modifications
function setModification() {
	//refresh property first
	refreshProperty();

	try { 
		document.getElementsByClassName('infobox')[0].style.display = 'none';
	} catch (err) { /** do we need to do something about this error? **/ }

	try {
		document.getElementById('mw-panel').style.display = 'none';
	} catch (err) { /** do we need to do something about this error? **/ }
	
	document.getElementById('content').style.marginLeft = '10px';
	document.getElementById('content').style.fontSize = ewprops.size +'px';
	document.getElementById('content').style.fontFamily = ewprops.font;
}

//reset modifications done by the set function
function resetModification() {
	try { 
		document.getElementsByClassName('infobox')[0].style.display = '';
	} catch (err) {
		/** do we need to do something about this error? **/
	}

	try {
		document.getElementById('mw-panel').style.display = '';
	} catch (err) { /** do we need to do something about this error? **/ }

	document.getElementById('content').style.marginLeft = '12em';
	document.getElementById('content').style.fontSize = '';
	document.getElementById('content').style.fontFamily = '';
}

//called by checkbox, for readmode in UI
function checkChange() {
	if (document.getElementById('ewcheckbox').checked) setModification();
	else resetModification();
}

/**
 * Code implement, scroll up/down of the EW menu, with document scroll
 */
var y1 = -50;var y2 = 2;
var currentPos = document.body.scrollTop;
function monitor(event){
	var dy = (currentPos - document.body.scrollTop) / 5;
	if (document.getElementById('easywiki').style.top == '')
		document.getElementById('easywiki').style.top = '2px';
	var y = parseInt(document.getElementById('easywiki').style.top) + dy;
	if (y > y2) y = y2;
	if (y < y1) y = y1;
	currentPos = document.body.scrollTop;
	document.getElementById('easywiki').style.top = y + 'px';

	//hide menu
	hideSubMenu();
}
document.body.onscroll = monitor;


/**
 * Adding search capability to easywiki
 */
function searchew(event) {
	var source = document.getElementById('ewsearch');

	if (event.which == 13 && source.value.length) {
		window.location.href = "http://en.wikipedia.org/wiki/w/index.php?search=" +source.value;
	}
}

document.getElementById('ewsearch').onkeyup = searchew;


//==================================================================
//for submenu
//==================================================================
function showHideSubMenu(event){

	var source = document.getElementsByClassName('ewmenu')[0];
	source = source.getElementsByTagName('span')[0];

	var obj = document.getElementsByClassName('ewsubmenu')[0];
	if (obj.style.display == "none"
		|| obj.style.display.length === 0) {
		obj.style.display = 'block';
		source.innerHTML = '&#x25B2';
		return;
	}
	obj.style.display = 'none';
	source.innerHTML = '&#x25BC;';
}

function hideSubMenu() {
	var obj = document.getElementsByClassName('ewsubmenu')[0];
	obj.style.display = "none";

	var source = document.getElementsByClassName('ewmenu')[0];
	source.getElementsByTagName('span')[0].innerHTML = '&#x25BC;';
}

var temp = document.getElementsByClassName('ewmenu')[0];
temp = temp.getElementsByTagName('span')[0];
temp.onclick = showHideSubMenu;
@@ -4307,8 +4307,514 @@
 SubMenu;
+%0A%0A//==================================================================%0A//add functionality to submenu%0A//==================================================================%0Atemp = document.getElementsByClassName('ewsubmenu')%5B0%5D;%0Atemp = temp.getElementsByTagName('div');%0Afor (var i = 0; i %3C temp.length; i++) %7B%0A%09var attr = temp%5Bi%5D.getAttribute('option');%0A%09if(attr == 'top') %7B%0A%09%09temp%5Bi%5D.onclick = function() %7B%0A%09%09%09document.body.scrollTop = 0;%0A%09%09%7D%0A%09%7D else if(attr == 'blacklist') %7B%0A%09%09//blacklist current url%0A%09%7D%0A%7D

Move to top implemented, blacklisting left