User:Ashlux/test.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. |
Documentation for this user script can be added at User:Ashlux/test. |
// <nowiki>
//////////////////////////////////////////
// Tabs by Korath
// returns <li><a href="url">name</a></li>
//////////////////////////////////////////
/**** Add tab as menu ****/
/**** The CSS for this to work is on the talk page. ****/
function addlimenu(tabs, name, id)
{
var na = document.createElement('a');
na.href = '';
var mn = document.createElement('ul');
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.className = 'tabmenu';
li.appendChild(na);
li.appendChild(mn);
tabs.appendChild(li);
return li;
}
/**** Add generic tab ****/
function addlilink(tabs, url, name, id){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.id = id;
li.appendChild(na);
tabs.appendChild(li);
return li;
}
//////////////////////////////////////////
//
// Init everything
//
//////////////////////////////////////////
/**** Generic custom talk message ****/
function autoMessage(msgtext, summary, saveopt, top)
{
var txt = document.editform.wpTextbox1;
document.editform.wpSummary.value = summary;
if(txt.value.length > 0) txt.value += '\n';
if (top == 'true')
{
txt.value = msgtext + txt.value;
}
else
{
txt.value += msgtext;
}
if(saveopt == 'save')
{
document.editform.submit();
}
else if(saveopt == 'preview')
{
document.editform.wpPreview.click();
}
else if(saveopt == 'diff')
{
document.editform.wpDiff.click();
}
}
function autoWikiProjectTemplateOnTalkPage()
{
if (document.title.indexOf('Editing ') == 0)
{
var action = '';
var target = '';
if (location.search)
{
var l = location.search.substring(1).split('&');
for (var i = 0; i < l.length; ++i)
{
var eq = l[i].indexOf('=');
var name = l[i].substring(0, eq);
if (name == 'fakeaction')
{
action = l[i].substring(eq + 1);
}
else if (name == 'faketarget')
{
target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' ');
}
} // end for
} // end if "location.search"
if (action == 'addtemplatetotop')
{
autoMessage("{{"+"WikiProject Oklahoma}}\n", "Add to [[Wikipedia:WikiProject Oklahoma]]", "preview", "true");
}
else if (action == 'addtorelatedchanges')
{
autoMessage("* [[" + target + "]]\n", "Add " + target + " to recent changes list", "preview", "false");
} // end if "action"
} // end if "Editing"
}
function wikiProjectTemplateOnTalkPage()
{
// TODO: THIS WILL NOT WORK FOR ALL LANGUAGES!
var pagename = document.title.replace(" - Wikipedia, the free encyclopedia", "");
var target = pagename;
window.open('/w/index.php?title=Talk:' + pagename + '&action=edit&fakeaction=addtemplatetotop&faketarget=' + target, pagename + ' add template', 'status,toolbar,location,menubar,directories,resizeable,scrollbars');
http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_Oklahoma/Oklahoma_recent_changes&action=edit
window.open('/w/index.php?title=Wikipedia:WikiProject_Oklahoma/Oklahoma_recent_changes' + '&action=edit&fakeaction=addtorelatedchanges&faketarget=' + pagename,
pagename + ' add to recent changes',
'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}
function asdf()
{
// these will be replaced...
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tabs, 'javascript:wikiProjectTemplateOnTalkPage()', '{{WP:OK}}', '');
// addlilink(tabs, 'http://www.ashlux.com/', 'Ashlux.com', 'ashlux.com');
// addlimenu(tabs, 'bcrat', 'bfunc');
// var bfunc = document.getElementById('bfunc').getElementsByTagName('ul')[0];
// addlilink(bfunc, 'asdf', 'make sysop', 'sysop');
}
$(asdf);
if (window.addEventListener) window.addEventListener('load', autoWikiProjectTemplateOnTalkPage, false);
else if (window.attachEvent) window.attachEvent('onload', autoWikiProjectTemplateOnTalkPage);
// </nowiki>