User:Jag123/StubScript.js

// <nowiki> var stubName = ""; var criteria = ""; var fnName = ""; var newDiv; var stubList = ""; function ref…

// <nowiki>
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 = "{{" + NewStub + "-stub}}"; // New stub to be added
var szEditSummary = "ch to " + szNewStub + " - [[Wikipedia: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 + '<a href="javascript:setStub(\'anatomy\');">Anatomy</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'chem\');">Chem</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'cellbio\');">Cell Bio</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'biosci\');">Biology</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'biochem\');">Biochem</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'bacteria\');">Bacteria</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'animal\');">Animal</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'plant\');">Plant</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'med\');">Medecine</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'physics\');">Physics</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'psychology\');">Psychology</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'astronomy\');">Astronomy</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'geology\');">Geology</a><br>';
// </nowiki>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.