User:Jared/monobook.js
From Wikipedia, the free encyclopedia
If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
//<pre> // This is based on the original code on Wikipedia:Tools/Editing tools // // The original code was on the project page and needed to be cut and paste to the user's // monobook.js page. However, this caused problems with the quote marks. So I have moved // it to its own page. // // I do not know a lot about Javascript so please do not ask for a complicated change //Interiot's javascript edit counter if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) { document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); } function InsertButtonsToToolBar() { tooly = document.getElementById('toolbar'); if (tooly != null) { StrikeTextButton = "<a href=\"javascript:insertTags('<s>','</s>','Insert text here');\"><img src=\"http://upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png\" alt=\"Strike\" title=\"Strike-through text\"></a>"; SupportVoteImageButton = "<a href=\"javascript:insertTags('* [[Image:Symbol support vote.png|15px]] '''Support.'''','','');\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Symbol_support_vote.png/15px-Symbol_support_vote.png\" alt=\"Support\" title=\"Support vote\"></a>"; OpposeVoteImageButton = "<a href=\"javascript:insertTags('* [[Image:Symbol oppose vote.png|15px]] '''Oppose.'''','','');\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Symbol_oppose_vote.png/15px-Symbol_oppose_vote.png\" alt=\"Oppose\" title=\"Oppose vote\"></a>"; NeutralVoteImageButton = "<a href=\"javascript:insertTags('* [[Image:Symbol neutral vote.png|15px]] '''Neutral.'''','','');\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Symbol_neutral_vote.png/15px-Symbol_neutral_vote.png\" alt=\"Neutral\" title=\"Neutral vote\"></a>"; } } window.onload = InsertButtonsToToolBar; function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title]; } } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; } function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key); } addOnloadHook(function() { if (document.title.search("/") != -1 || document.title.search("- History -") != -1) { //no subpages or history return; } if (document.title.indexOf("User:") == 0) { username_a = document.URL.match(/:.*:(.*)/); username=username_a[1]; addTab("http://en.wikipedia.org/w/index.php?title=User_talk:" + username + "&action=edit§ion=new", "+", "", "Add new comment to user page.", ""); addTab("http://en.wikipedia.org/wiki/Special:Contributions/" + username, "contribs", "ca-contrib", "Contribs", ""); addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=move&user=" + username, "page moves", "ca-pagemoves", "Page moves", ""); addTab("http://en.wikipedia.org/wiki/User:Interiot/Tool2/code.js?username=" + username, "Edit count", "", "Edit count", ""); } }); addOnloadHook(function () { for (var i=0; i<document.links.length; ++i) { if (document.links[i].href.indexOf('Special:Watchlist')>0) { document.links[i].href+='?hideOwn=1'; break; } } }); 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; } 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); // This will add an [edit top] link at the top of all pages except preview pages // by User:Pile0nades // Add an [edit top] link to pages addOnloadHook(function () { // if this is preview page or generated page, stop if(document.getElementById("wikiPreview") || window.location.href.indexOf("/wiki/Special:") != -1) return; // get the page title var pageTitle = document.title.split(" - ")[0].replace(" ", "_"); // create div and set innerHTML to link var divContainer = document.createElement("div"); divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-right:15px;margin-top:3px;">[<a href="/w/index.php?title='+pageTitle+'&action=edit&section=0" title="'+document.title.split(" - ")[0]+'">edit top</a>]</div>'; // insert divContainer into the DOM before the h1 if(window.location.href.indexOf("&action=edit") == -1) document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]); if(window.location.href.indexOf("&action=edit§ion=0") != -1) document.getElementById("wpSummary").value = "/* Intro */ "; }); gsTimeInsertBefore = ''; // leave blank to append after "logout" // function makeTime() { var li = document.createElement( 'li' ); li.id = 'pt-time'; var mySpan = document.createElement( 'span' ); mySpan.appendChild( document.createTextNode( '00:00:00' ) ); li.appendChild( mySpan ); if ( ! gsTimeInsertBefore ) { // append to end (right) of list document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); } else { var before = document.getElementById( gsTimeInsertBefore ); before.appendChild( li, before ); } doTime = window.setTimeout("getTime()", 1000); } addOnloadHook( makeTime ); function getTime() { var time = new Date(); var hours = time.getUTCHours(); if (hours < 10) { hours = "0" + hours; } var minutes = time.getUTCMinutes(); if (minutes < 10) { minutes = "0" + minutes; } var seconds = time.getUTCSeconds(); if (seconds < 10) { seconds = "0" + seconds; } var currentTime = hours + ":" + minutes + ":" + seconds; document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 8, currentTime); doTime = window.setTimeout("getTime()", 1000); } var flameviper = new Object(); flameviper.util = { getobj:function(id) { return document.getElementById ? document.getElementById(id) : document.all[id]; }, add:function(parent, tag, attr) { var el = document.createElement(tag); if (attr) { for (key in attr) { el[key] = attr[key]; } } return parent.appendChild(el); }, mousebtnmap:{ ns:[null,1,3,2], ie:[null,1,2,null,3] }, xmlhttpreq:function() { if (window.XMLHttpRequest) { xmlhttpobj = new XMLHttpRequest() } else { try { xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttpobj = null; } } } return xmlhttpobj; } }; flameviper.comm = { doreq:function(url,postdata,headers) { var req = flameviper.util.xmlhttpreq(); req.open(postdata?"POST":"GET", url, false); for(header in headers) { req.setRequestHeader(header,headers[header]); } req.send(postdata||null); return req; } }; flameviper.wputil = { username:function() { return wgUserName; //return flameviper.util.getobj("pt-userpage").childNodes[0].childNodes[0].nodeValue; }, iseditpage:function() { return document.title.indexOf("Editing ")==0; }, pagename:function() { var iseditpage = flameviper.wputil.iseditpage(); return document.title.substr(iseditpage?8:0,document.title.indexOf(" - ")-(iseditpage?8:0)); }, addsidepanel:function(id,label) { var div = flameviper.util.add(flameviper.util.getobj("column-one"), "div", {className:"portlet",id:id}); flameviper.util.add(div, "H5").innerHTML = label; flameviper.util.add(flameviper.util.add(div, "div", {className:"pBody"}), "ul"); }, addsidepanelbutton:function(id,label,targhref) { var li = flameviper.util.add((flameviper.util.getobj(id).getElementsByTagName("ul"))[0],"li"); with(flameviper.util.add(li,"a")) { innerHTML = label; href = targhref; } return li; }, setpagecontent:function(pagename,content,summary,watch) { var prelimresp = flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=submit"); var edittime = prelimresp.responseText.match(/\<input type='hidden' value="(\d+)" name="wpEdittime" \/\>/)[1]; var edittoken = prelimresp.responseText.match(/\<input type='hidden' value="([0-9a-f]+)" name="wpEditToken" \/\>/)[1]; flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=submit", "wpEdittime="+edittime+ "&wpEditToken="+edittoken+ "&wpTextbox1="+escape(content)+ "&wpSummary="+escape(summary)+ (watch?"&wpWatchthis=on":"")+ "&wpSection=&wpSave=Save+page", {"Content-Type":"application/x-www-form-urlencoded"}); }, getpagecontent:function (pagename) { var req = flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=edit"); var content = req.responseText.match(/\<textarea[\w\W]*?\>([\w\W]*?)\<\/textarea\>/)[1]; content = content.replace(/\<\;/gi, "<"); content = content.replace(/\>\;/gi, ">"); content = content.replace(/\"\;/gi, "\""); content = content.replace(/\&\;/gi, "&"); return content; } }; flameviper.statuschanger = new Object(); /* configuration */ // change these to whatever you'd like to show up on your status page. flameviper.statuschanger.statuscode = { online:'{{{2|<font color= "green">online</font> [[Category:Wikipedians who are currently online|JP06035]]}}}', busy:'{{{3|<font color= "blue">on wikivacation</font>}}}', offline:'{{{4|<font color= "red">offline</font>}}}' }; // true to use the personal bar, false to create a panel in the left column flameviper.statuschanger.usepersonalbar = true; // true if you'd like your status page on your watchlist flameviper.statuschanger.watchstatus = {{{watch|false}}}; /* end configuration */ flameviper.statuschanger.oldonload = window.onload; window.onload = function() { if (typeof flameviper.statuschanger.oldonload == "function"){setTimeout('flameviper.statuschanger.oldonload()',50);} if (flameviper.statuschanger.usepersonalbar) { var a = flameviper.wputil.addsidepanelbutton("p-personal", "Online", 'javascript:flameviper.statuschanger.setstatus("online")' ); var b = flameviper.wputil.addsidepanelbutton("p-personal", "Offline", 'javascript:flameviper.statuschanger.setstatus("offline")' ); var c = flameviper.wputil.addsidepanelbutton("p-personal", "Vacation", 'javascript:flameviper.statuschanger.setstatus("busy")' ); a.style.borderRight=b.style.borderRight="1px solid #aaaaaa"; b.style.marginLeft=c.style.marginLeft="0px"; a.style.paddingRight=b.style.paddingLeft=b.style.paddingRight=c.style.paddingLeft="2px"; } else { flameviper.wputil.addsidepanel("tz-statuschanger", "status changer"); flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Online", 'javascript:flameviper.statuschanger.setstatus("online")' ); flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Busy", 'javascript:flameviper.statuschanger.setstatus("busy")' ); flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Offline", 'javascript:flameviper.statuschanger.setstatus("offline")' ); } }; flameviper.statuschanger.setstatus = function(statusname) { flameviper.wputil.setpagecontent( "User:"+flameviper.wputil.username()+"/Status", flameviper.statuschanger.statuscode[statusname], statusname, flameviper.statuschanger.watchstatus); }; // [[User:Outriggr/metadatatest.js]] importScript('User:Outriggr/metadatatest.js'); defaultProject = "OlympicsWikiProject"; importScript('User:AzaToth/twinkle.js'); //</pre>