User:Mangostar/monobook.css

// //This function adds a link to the toolbox which, when clicked, displays the size of the page //and the size of the prose. See the talk page for more details. // //This function requires the addLink function. If you do not already have it, //add User:Omegatron/monobook.js/addlink.js to your monobook.js. // //To use this function add User:Dr pda/prosesize.js to your monobook.js // function loadXMLDoc(url,handler, page) {   // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { var req = new XMLHttpRequest; }   // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { var req = new ActiveXObject("Microsoft.XMLHTTP"); }  if (req) { req.onreadystatechange = function {handler(req, page)}; req.open("GET", url, true); req.send(""); } } function getWikiText(req, page) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... response = req.responseText; var startindex = response.indexOf('&#x00BB;'); startindex = response.indexOf('title="'+page+'"',startindex); var endindex = response.indexOf('',startindex); if(startindex > -1){ searchresult = response.substr(startindex,endindex-startindex); result = searchresult.match(/\d+\.\d [Kk]i?B \(\d+ words\)/); wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: '+result; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); }	 else{ //alert("There was a problem using the Wikipedia Search to find the wiki text size\nEither the search is not working or the correct article did not appear on the first page of results"); wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: Problem with search'; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); }       } else { alert("There was a problem retrieving the XML data:\n" +               req.statusText); }   } } function getFileSize(req) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... var fsize = req.responseText.length; window.status = fsize; var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+(fsize/1024).toFixed(0)+' kB'; var output = document.getElementById("document-size-stats"); var prose_html_value = document.getElementById("prose-size-html"); output.insertBefore(total_value,prose_html_value); } else { alert("There was a problem retrieving the XML data:\n" +               req.statusText); }   } } function getLength(id){ var textLength = 0; for(var i=0;i<id.childNodes.length; i++){ if(id.childNodes[i].nodeName == '#text'){ textLength += id.childNodes[i].nodeValue.length; } else{ textLength += getLength(id.childNodes[i]); } } return textLength; } function getDocumentSize{ var bodyContent = document.getElementById("bodyContent"); if(document.getElementById("document-size-stats")){ //if statistics already exist, turn them off and remove highlighting var output = document.getElementById("document-size-stats"); var oldStyle = output.className; var pList = bodyContent.getElementsByTagName("p"); for(var i=0;i<pList.length; i++){ if(pList[i].className != 'catlinks') pList[i].style.cssText = oldStyle; }  output.parentNode.removeChild(output); var header = document.getElementById("document-size-header"); header.parentNode.removeChild(header); } else{ var output = document.createElement("ul"); output.id = "document-size-stats"; var prose_html_value = document.createElement("li"); prose_html_value.id = "prose-size-html"; output.appendChild(prose_html_value); var ref_html_value = document.createElement("li"); ref_html_value.id = "ref-size-html"; output.appendChild(ref_html_value); var prose_value = document.createElement("li"); prose_value.id = "prose-size"; output.appendChild(prose_value); output.className = bodyContent.getElementsByTagName("p").item(0).style.cssText; var ref_value = document.createElement("li"); ref_value.id = "ref-size"; output.appendChild(ref_value); var dummy = document.getElementById("siteSub"); dummy.parentNode.insertBefore(output, dummy.nextSibling); var header = document.createElement("span"); header.id = "document-size-header"; header.innerHTML = ' Document statistics: (See here for details.) '; dummy.parentNode.insertBefore(header,output); //If browser supports document.fileSize property (IE) if(document.fileSize){ var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+(document.fileSize/1024).toFixed(0)+' kB'; output.insertBefore(total_value,prose_html_value); } else{ loadXMLDoc(location.pathname,getFileSize) } //Get size of images only if browser supports filesize property (IE) var iList = bodyContent.getElementsByTagName("img"); if(iList.length >0 && iList[0].fileSize){ //Get size of images included in document var image_size = 0; var first_magnify = true; for (var i=0;i<iList.length; i++){ var im = iList[i]; if(im.getAttribute("src").indexOf("magnify-clip.png") != -1){ if(first_magnify){ image_size += im.fileSize*1; first_magnify = false; }   }    else{ image_size += im.fileSize*1; }  }   var image_value = document.createElement("li"); image_value.id = "image-size"; image_value.innerHTML='Images: '+(image_size/1024).toFixed(0)+' kB'; output.appendChild(image_value); } //Calculate prose size var pList = bodyContent.getElementsByTagName("p"); prose_size = 0; prose_size_html = 0; word_count = 0; for(var i=0;i]+)>)/ig,"").split(' ').length para.style.cssText = "background-color:yellow"; } } //Calculate size of reference markers ([1] etc) var rmList = bodyContent.getElementsByTagName("sup"); refmark_size = 0; refmark_size_html = 0; for(var i=0;i<rmList.length; i++){ var refmark = rmList[i]; if(refmark.className == "reference"){ refmark_size += getLength(refmark); refmark_size_html += refmark.innerHTML.length; } } prose_value.innerHTML='Prose size (text only): '+((prose_size-refmark_size)/1024).toFixed(0)+' kB ('+word_count+' words)'; prose_html_value.innerHTML='Prose size (HTML): '+((prose_size_html-refmark_size_html)/1024).toFixed(0)+' kB'; //Calculate size of references (i.e. output of ) var rList = bodyContent.getElementsByTagName("ol"); var ref_size = 0; var ref_size_html = 0; for (var i=0; i<rList.length; i++){ if(rList[i].className == "references"){ ref_size = getLength(rList[i]); ref_size_html = rList[i].innerHTML.length; } } ref_value.innerHTML='References (text only): '+((ref_size+refmark_size)/1024).toFixed(0)+' kB'; ref_html_value.innerHTML='References (HTML): '+((ref_size_html+refmark_size_html)/1024).toFixed(0)+' kB'; //get correct name of article from first h1 tag //Use this instead of location.pathname in order to handle redirects var pageNameSpaces = document.getElementsByTagName("h1").item(0).innerHTML; var pageNameUnderscores = pageNameSpaces.replace(/ /g,'_') //if page is a permalink, diff, etc don't try to search if(!location.pathname.match('/w/index.php')){ //Get size as returned by Wikipedia search var searchURL = '/wiki/Special:Search?search=' + pageNameUnderscores + '&fulltext=Search'; loadXMLDoc(searchURL,getWikiText,pageNameSpaces); } } } addOnloadHook(function {  if(!document.forms.editform){    addLink('p-tb', 'javascript:getDocumentSize', 'Page size', 't-page-size', 'Calculate page and prose size', , );  } }); //