User:Decltype/test.js

// Misc. javascript experimentation. Some code lifted from Shubinators DYKChecker var onTTDYK, nextSection, urlJump, sections, currentTitle; var partsProcessing, articleTitles, dates, nom5x; var dateFormat, hookLengthYellow, hookLengthRed, check5xNoms, unlock, fixedSidebar; //configurable options if (!hookLengthYellow) hookLengthYellow = 200; if (!hookLengthRed) hookLengthRed = 220; if (!check5xNoms) check5xNoms = "ifnom5x"; if (!fixedSidebar) fixedSidebar = "onttydk"; function scanArticle(title, output, html) { // the meat of the DYKcheck tool // calculates prose size of the given html // checks for inline citations and stub templates in the given html // passes info to checkTalk, getFirstRevision, checkMove, and checkExpansion if (!onTTDYK || (check5xNoms == "always") || (check5xNoms == "ifnom5x" && nom5x)) { partsProcessing = new Array(4); } else { partsProcessing = new Array(3); }	dates = new Array(3); var proseDisp = document.createElement("li"); proseDisp.id = "dyk-prose"; output.appendChild(proseDisp);

// check if article is stub if (html.innerHTML.indexOf('id="stub"') != -1 || html.innerHTML.indexOf('id=stub') != -1) { var stubAlert = document.createElement("li"); stubAlert.id = "stub-alert"; output.appendChild(stubAlert); stubAlert.innerHTML = 'Article is classified as a stub'; stubAlert.style.cssText = "background-color:yellow"; } } function checkDocument { // prepares for scan and passes info to scanArticle onTTDYK = false; if (document.getElementById("dyk-stats-0")) { clearStats; } else { var output = document.createElement("ul"); output.id = "dyk-stats-0"; var dummy = document.getElementById("siteSub"); dummy.parentNode.insertBefore(output, dummy.nextSibling); createHeaderAndProcessing(output); currentTitle = 0; var normalizedTitle = wgTitle.replace("%","%25").replace("+","%2B").replace("/","%2F"); normalizedTitle = normalizedTitle.replace("?","%3F").replace("#","%23").replace("&","%26"); if (wgNamespaceNumber == 2) { normalizedTitle = "User:" + normalizedTitle; }		scanArticle(normalizedTitle, output, getBody); } } function checkTitle(title, output, i) { // gets the given title from Wikipedia's server and passes it to scanArticle var normalizedTitle = title.replace("%","%25").replace("+","%2B").replace("/","%2F"); normalizedTitle = normalizedTitle.replace("?","%3F").replace("#","%23").replace("&","%26"); var api = sajax_init_object; api.open('GET', '/w/index.php?title=' + normalizedTitle + '&action=render', true); api.onreadystatechange = function { if (api.readyState == 4) { if (api.status == 200) { var ttdykTemp = document.createElement("div"); ttdykTemp.id = "ttdyk-temp" + i;				ttdykTemp.innerHTML = api.responseText; scanArticle(normalizedTitle, output, ttdykTemp); } else { alert("XML error"); }		}	};	api.send(null); } function getBody { // gets the HTML body of the page // taken from the prosesize tool (http://en.wikipedia.org/wiki/User:Dr_pda/prosesize.js) var contentName; if (skin == 'monobook' || skin == 'chick' || skin == 'myskin' || skin == 'simple') { contentName = 'bodyContent'; } else if (skin == 'modern') { contentName = 'mw_contentholder'; } else if (skin == 'standard' || skin == 'cologneblue' || skin == 'nostalgia') { contentName = 'article'; } else { // fallback case; the above covers all currently existing skins contentName = 'bodyContent'; }	// Same for all skins if previewing page if (wgAction == 'submit') contentName = 'wikiPreview'; return document.getElementById(contentName); }

function dykCheck { 	// this function for casual use and anons if (((wgAction == 'view' || wgAction == 'submit') && (wgNamespaceNumber == 0 || wgNamespaceNumber == 2)) ) {		checkDocument; } }