User:Gnorthup/monobook.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
rmEditButtons=['all']
importScript('User:MarkS/extraeditbuttons.js'); //[[User:MarkS/extraeditbuttons.js]]
// [[User:ais523/bracketmatch.js]] - Colour matching brackets in a copy of the edit box.
// By [[User:ais523]], on a suggestion by [[User:Absidy]].
addOnloadHook(function(){
var p=document.getElementById('wikiPreview');
if(p==null) p=document.getElementById('viewsourcetext');
if(p)
p.innerHTML+="<div id='bm_parseres'><a href='javascript:bm_parsebrackets();'>Parse</a></div>";
});
function bm_parsebrackets()
{
var t=document.getElementById('wpTextbox1').value;
var a=sajax_init_object();
var p='action=expandtemplates&generatexml=1&format=json&callback=bm_callback&text='+encodeURIComponent(t);
a.open('POST', wgServer+wgScriptPath+'/api.php');
a.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
a.setRequestHeader("Content-length", p.length);
a.setRequestHeader("Connection", "close");
a.onreadystatechange=function(){bm_apirespond(a)};
a.send(p);
}
function bm_apirespond(a)
{
try
{
if(a.readyState==4)
eval(a.responseText);
}
catch(e)
{
document.getElementById('bm_parseres').innerHTML=
"Could not parse due to a server error. <a href='javascript:bm_parsebrackets();'>Parse</a>";
}
}
var colang;
function bm_hexdigit(n)
{
var i=Math.floor(n);
if(i<10) return i+'';
if(i==10) return 'A';
if(i==11) return 'B';
if(i==12) return 'C';
if(i==13) return 'D';
if(i==14) return 'E';
if(i==15) return 'F';
}
function bm_tohex(n)
{
var i=Math.floor(n);
return bm_hexdigit(i/16)+bm_hexdigit(i%16);
}
function bm_gencol(ang)
{
var r=Math.sin(ang)+1;
var g=Math.sin(ang+3.14159*2/3)+1;
var b=Math.sin(ang-3.14159*2/3)+1;
return bm_tohex(r*127.5)+bm_tohex(g*127.5)+bm_tohex(b*127.5);
}
function bm_callback(o)
{
var subs={"tplarg":"{{{",
"/tplarg":"}}}",
"template":"{{",
"/template":"}}",
"part":"|",
"ext":"&"+"lt;",
"/attr":"&"+"gt;",
"attr/":"&"+"gt;"};
var h=o.parsetree["*"].split("<");
var i=h.length;
var r;
var n;
var sp=0;
var st=new Array();
var col;
colang=0;
while(--i)
{
col="";
n=1;
h[i]=h[i].split(">");
h[i][0]=h[i][0].split(" ");
r=subs[h[i][0][0]];
if(r==undefined) r="";
if(r=='}}}'||r=='}}')
{
st[sp]=bm_gencol(colang);
col=st[sp];
sp++;
colang+=2.4; //golden angle in radians, approx
}
else if(r=='{{{'||r=='{{')
{
sp--;
col=st[sp];
n=2;
}
if(col!="")
r="<font color='#"+col+"' id='bm_f"+col+n+"' onclick='bm_highlight(\""+col+"\",\"black\")'>"+r+"</font>";
h[i][0]=r;
h[i]=h[i].join("");
}
document.getElementById('bm_parseres').innerHTML=
"<div style='border:1px solid blue'><tt>"+h.join("").split("\n").join("<br />")+
"</tt></div><div><a href='javascript:bm_parsebrackets();'>Parse</a></div>";
}
function bm_highlight(x,c)
{
document.getElementById('bm_f'+x+'1').style.backgroundColor=c;
document.getElementById('bm_f'+x+'2').style.backgroundColor=c;
if(c=="black")
window.setTimeout("bm_highlight('"+x+"','transparent')",3000);
}
//<pre>
//test: {{{a|b}}} {{a|b}} {{c|{{e|a=b|3=c}}|f}}<imagemap type=c>abc</imagemap>
//test: <i>f</i><nowiki>g</nowiki><includeonly>h</includeonly>
//test: <noinclude>i</noinclude> {{{{{{{{j}}}}}}}}
/* test:
{{startofline}}</pre>
*/
/*
Usage :Include a call to addForceSummary() in your page load function
Possible improvements :Make any form submission force a summary. Note that requiring an edit summary on preview or diff is not useful since "save" still needs to gain focus or be clicked before a commit can occur.
A heavily modified and expanded version of this code is now in use across the entire SourceWatch wiki. Here's a direct link to the code. A particular enhancement in the SourceWatch code is that it provides a dropdown next to the edit summary textfield containing common edit summaries. Selecting one of these automatically inserts that summary into the textfield. The code also examines which subproject of SourceWatch the page belongs to, and adds an appropriate prefix to the edit summary.
*/
function addForceSummary()
{
if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return;
if(/§ion=new/.test(window.location.href)) return;
if(!document.forms.editform) return;
document.forms.editform.wpSave.onclick = forceSummary;
// The second invocation of this will cause extra annoyance if there is no edit summary present. If there *is* an edit summary, the dialog box will not appear.
document.forms.editform.wpSave.onfocus = forceSummary;
}
function forceSummary()
{
if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1'))
{
var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',document.forms.editform.wpSummary.value);
if(r == null) { return false; }
document.forms.editform.wpSummary.value = r;
}
return true;
}
addOnloadHook(addForceSummary);
/*
*/
//////////STATUS CHANGER
// Creator: Misza13
// Credits: Voyagerfan5761 for some minor improvements
// Modified by Xenocidic to simply use /Status as a one word indicator,
// compatible with {{Statustop}} for display
addOnloadHook(function (){
//Check if the config is defined
if (typeof(statusChangerConfig) == 'undefined') {
statusChangerConfig = {}
}
if (typeof(statusChangerConfig.statusList) == 'undefined') {
statusChangerConfig.statusList = [ 'online', 'busy', 'around', 'offline' ];
}
if (typeof(statusChangerConfig.statusPage) == 'undefined') {
statusChangerConfig.statusPage = 'User:' + wgUserName + '/Status';
}
//Add the links
for (var i=0; i<statusChangerConfig.statusList.length; i++) {
var stat = statusChangerConfig.statusList[i];
addPortletLink(
"p-personal", //target tab - personal links
wgServer + wgScript + "?title=" + statusChangerConfig.statusPage + "&action=edit&newstatus=" + stat, //link URL
stat, //link text
"pt-status-" + stat, //id of new button
"I'm " + stat + "!", //hover text
"", //???
document.getElementById("pt-logout")); //add before logout button
}
if (location.href.indexOf("&action=edit&newstatus=") == -1) return; //Are we here to auto-edit the status?
//Get new status
statusRegExp = /&action=edit&newstatus=(.*)/;
status = statusRegExp.exec(location.href)[1];
//Modify the form
document.getElementById('wpTextbox1').value = status;
document.getElementById('wpSummary').value = wgUserName + " is now " + status +".";
document.getElementById('wpMinoredit').checked = true;
//Submit it!
document.getElementById('editform').submit();
});
//[[Category:Wikipedia scripts|statusChanger]]