User:Rcstraus/common.js

$(document).ready(function {	$('  ').insertAfter( ".mw-jump" );

//will prevent redirection when link is clicked $("a").click(function(e) { e.preventDefault; });

var elements = document.getElementsByTagName('a'); for(var i = 0; i < elements.length; i++) { elements[i].onclick = function (e) { var responseLink = httpGet(e.target); }	}

function httpGet(url){ var xhr = new XMLHttpRequest; xhr.open('GET', url, true); xhr.responseType = 'document';

xhr.onload = function { if (xhr.readyState === xhr.DONE) { if (xhr.status === 200) { response = xhr.response.getElementById("mw-content-text").textContent; var text = getWordFrequency(response); document.getElementById("someID").innerText = text; }   		}		};		xhr.send(null); return ""; }	function getWordFrequency(response){ var str = String(response).toLowerCase; var sortedWords = handleWords(str); sortedWords.splice(0, 100);

var text = ""; for(var i = 0; i < 25; i++) { text += sortedWords[i].name + " = " + sortedWords[i].frequency + " "; }       return text; }	function handleWords(string){ var wordsArray = string.split(/\s+/); var wordsMap = buildWordMap(wordsArray); var sortedWords = sortWordMap(wordsMap); return sortedWords; }	function buildWordMap(wordsArray){ //create a map to hold words var wordsMap = {}; wordsArray.forEach(function (key) {   		if (wordsMap.hasOwnProperty(key)) {      			wordsMap[key]++;    		} else {      		  wordsMap[key] = 1;    		}  		}); return wordsMap; }	function sortWordMap(wordsMap){ // sort by count in descending order var sortedWords = []; sortedWords = Object.keys(wordsMap).map(function(key) {   		return {      			name: key,      			frequency: wordsMap[key]    		};  		}); sortedWords.sort(function(x, y) {   		return y.frequency - x.frequency;  		}); return sortedWords; } });