User:Onco p53/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin can be added at User:Onco p53/monobook.css. |
var stubName = "";
var criteria = "";
var fnName = "";
var newDiv;
var stubList = "";
var szCategories = "";
var szCategoryName = "";
function reformatMyPage() {
clearTopLinks();
recreateTopLinks();
addToolbox();
}
function clearTopLinks()
{
var obj = document.getElementById('p-personal').children.item(1).children.item(0);
var l = obj.children.length;
for (x=0; x < l; x++)
{
var objChild = obj.children(0);
obj.removeChild(objChild);
}
}
function recreateTopLinks()
{
var obj = document.getElementById('p-personal').children.item(1).children.item(0);
var objLI;
// Jag123
objLI = createLI('pt-userpage');
objLI.appendChild(createA('/wiki/User:Jag123','Jag123'));
obj.appendChild(objLI);
// my talk
objLI = createLI('pt-mytalk');
objLI.appendChild(createA('/wiki/User_talk:Jag123','my talk'));
obj.appendChild(objLI);
// my stuff
objLI = createLI('pt-mytalk');
objLI.appendChild(createA('/wiki/User:Jag123/MyStuff','my stuff'));
obj.appendChild(objLI);
// Watchlist
objLI = createLI('pt-watchlist');
objLI.appendChild(createA('/wiki/Special:Watchlist','Watchlist'));
obj.appendChild(objLI);
// preferences
objLI = createLI('pt-preferences');
objLI.appendChild(createA('/wiki/Special:Preferences','Prefs'));
obj.appendChild(objLI);
// Contributions
objLI = createLI('pt-mycontris');
objLI.appendChild(createA('/w/index.php?title=Special:Contributions&target=Jag123','Contribs'));
obj.appendChild(objLI);
// Logout
objLI = createLI('pt-logout');
objLI.appendChild(createA('/w/index.php?title=Special:Userlogout&returnto=User:Jag123/monobook.js','Log out'));
obj.appendChild(objLI);
}
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.getElementById('wpSave').click();
} else window.alert('Could not find stub message');
}
function addCat(CatName)
{
//--Variables--//
var szNewCat = "[[Category:" + CatName + "]]"; // New stub to be added
var szEditSummary = "+cat"; // Edit Summary message
var bAutoSave = true; // Automatically 'Click' Save Page?
var bCheckMinor = true;
//-----------//
var ta = document.getElementsByTagName("textarea")(0);
if (ta == null) return;
ta.innerText = ta.innerText + "\r\n" + szNewCat;
var txtSummary = findSummaryTag();
txtSummary.value = szEditSummary;
if (bCheckMinor) checkMinorEdit();
if (bAutoSave) document.all['wpSave'].click();
}
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.getElementById('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 openCat()
{
var sz = szCategories;
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 = "szCategoryName == ''";
fnName = "addCat(szCategoryName);";
fnRun();
}
function addToolbox()
{
var objUL = document.getElementById('p-tb').children(1).children(0);
var objHR = document.createElement('hr');
objUL.appendChild(objHR);
AddToolboxLink("Javascript:openStub();","Open Stubs","StubWin");
AddToolboxLink("Javascript:openCat();","Open Cats","CatWin");
}
function fnRun()
{
if (eval(criteria))
{
setTimeout("fnRun();",500);
} else
{
eval(fnName);
}
}
function setStub(data)
{
stubName = data;
}
function setCat(data)
{
szCategoryName = 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(\'phys\');">Physics</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'psych\');">Psychology</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'astro\');">Astronomy</a><br>';
stubList = stubList + '<a href="javascript:setStub(\'geol\');">Geology</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Chemistry\');">Chemistry</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Biology\');">Biology</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Biochemistry\');">Biochemistry</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Physics\');">Physics</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Earth sciences\');">Earth sciences</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Mythology\');">Mythology</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Science\');">Science</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Literature\');">Literature</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Language\');">Language</a><br>';
szCategories = szCategories + '<a href="javascript:setCat(\'Arts\');">Arts</a><br>';