User:Jag123/StubScript.js

// var stubName = ""; var criteria = ""; var fnName = ""; var newDiv; var stubList = "";

function reformatMyPage {

addToolbox;

}

function createA(href,label) { var obj = document.createElement("A"); obj.href = href; obj.innerText = label;

return obj; }

function createLI(id) { var obj = document.createElement("LI"); obj.id = id; return obj; }

function changeStub(NewStub) { //--Variables--// var szNewStub = ""; // New stub to be added var szEditSummary = "ch to " + szNewStub + " - WikiProject Stub sorting"; // Edit Summary message var bAutoSave = true; // Automatically 'Click' Save Page? var bCheckMinor = true; //---//

var ta = document.getElementsByTagName("textarea")(0); if (ta == null) return; var szArticle = ta.innerText; var lPos = szArticle.indexOf('stub}}'); var lStartPos = 0; var x = 0; var bFound = false; while (lStartPos == 0) { x++ if (szArticle.substr(lPos - x,2) == "{{") lStartPos = lPos - x ;

if (x>20) lStartPos = -1; }

var szArticleEdit = '';

if (lStartPos >0) {	szArticleEdit = szArticle.substr(0,lStartPos) + szNewStub + szArticle.substr(lPos+6,szArticle.length); ta.innerText = szArticleEdit;

var txtSummary = findSummaryTag; txtSummary.value = szEditSummary; if (bCheckMinor) checkMinorEdit; if (bAutoSave) document.all['wpSave'].click; } else window.alert('Could not find stub message');

}

function findSummaryTag {	var col = document.getElementsByTagName('input'); for (var x =0; x < col.length; x++) if (col(x).name == 'wpSummary') break; return col(x) }

function checkMinorEdit {	var col = document.getElementsByTagName('input'); for (var x =0; x < col.length; x++) if (col(x).name == 'wpMinoredit') { col(x).checked = "true"; break; } }

function AddToolboxLink(link,title,id) { var objUL = document.all['p-tb'].children(1).children(0); objLI = createLI('but' + id + 'Stub'); objLI.appendChild(createA(link,title)); objUL.appendChild(objLI);

}

function openStub {

var sz = stubList;

newDiv = document.createElement('div'); newDiv.innerHTML = sz;

newDiv.style.position = "absolute"; newDiv.style.backgroundColor = "#0099CC"; newDiv.style.visibility = "visible";

document.all['p-tb'].children(1).children(0).appendChild(newDiv);

criteria = "stubName == ''"; fnName = "changeStub(stubName);";

fnRun;

}

function addToolbox {

var objUL = document.all['p-tb'].children(1).children(0); var objHR = document.createElement('hr'); objUL.appendChild(objHR);

AddToolboxLink("Javascript:openStub;","Open Stubs","StubWin"); }

function fnRun { if (eval(criteria)) {	setTimeout("fnRun;",500); } else {	eval(fnName); } }

function setStub(data) { stubName = data;

}

/////////////////////////////////////////////// if (window.addEventListener) window.addEventListener("load",reformatMyPage,false); else if (window.attachEvent) window.attachEvent("onload",reformatMyPage);

stubList = stubList + 'Anatomy '; stubList = stubList + 'Chem '; stubList = stubList + 'Cell Bio '; stubList = stubList + 'Biology '; stubList = stubList + 'Biochem '; stubList = stubList + 'Bacteria '; stubList = stubList + 'Animal '; stubList = stubList + 'Plant '; stubList = stubList + '<a href="javascript:setStub(\'med\');">Medecine</a> '; stubList = stubList + '<a href="javascript:setStub(\'physics\');">Physics</a> '; stubList = stubList + '<a href="javascript:setStub(\'psychology\');">Psychology</a> '; stubList = stubList + '<a href="javascript:setStub(\'astronomy\');">Astronomy</a> '; stubList = stubList + '<a href="javascript:setStub(\'geology\');">Geology</a> '; //