User:Melchoir/monobook.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
/* ==Popups== From [[User:Lupin/popups.js]]. <pre><nowiki>*/ //document.write('<script type="text/javascript" src="' // + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' // + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); // //popupImages=false; /*</nowiki></pre> ==Pipes in History== From [[User:HorsePunchKid/monobook.js]]. <pre><nowiki>*/ window.onload = Main; function Main() { addPipesToHistory(); } // Add a pipe to make using Template:Unsigned2 easier. function addPipesToHistory() { if(document.title.indexOf("- History -") > 0) { var items=getElementsByClass(document, "history-user", "span"); for(i=0;i<items.length;i++) { var hidden=document.createElement("span"); hidden.appendChild(document.createTextNode("|")); hidden.setAttribute("style", "color: white;"); items[i].childNodes[0].insertBefore(hidden, items[i].childNodes[0].childNodes[0]); } } } /*</nowiki></pre> ==Functions== ===addLink=== From [[Wikipedia:WikiProject User scripts/Scripts/addLink]]. <pre><nowiki>*/ function addLink(where, url, name, id, title, key, after){ //* where is the id of the toolbar where the button should be added; // i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb". // //* url is the URL which will be called when the button is clicked. // javascript: urls can be used to do more complex things. // //* name is what will appear as the name of the button. // //* id is the id of the button; it's best to define one. // Use a prefix to make sure its unique. Optional. // //* title is the tooltip title that gives a longer description // of the button; if you define a accesskey, mention it here. Optional. // //* key is the char you want for the accesskey. Optional. // //* after is the id of the button you want to follow this one. Optional. // 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); var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; if(after) { tabs.insertBefore(li,document.getElementById(after)); } else { 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; } /*</nowiki></pre> ===Add LI Link=== From [[Wikipedia:WikiProject User scripts/Scripts/Add LI link]]. <pre><nowiki>*/ 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; } /*</nowiki></pre> ==Edit top== From [[Wikipedia:WikiProject User scripts/Scripts/Edit Top]] by User:Pile0nades. This will add an [edit top] link at the top of all pages except preview pages <pre><nowiki>*/ 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§ion=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 */ "; }); /*</nowiki></pre> ==Toolbox== ===Logs=== From [[Wikipedia:WikiProject User scripts/Scripts/Logs link]]. Adds a 'logs for this page' link to the navigation bar. If the page is a user's page, talk page or subpage, the link will go to logs for the user instead. If the page is a special page, then no link is displayed. <pre><nowiki>*/ addOnloadHook(function () { // get page title var pagetitleRe=/[^:]*:\/\/en\.wikipedia\.org\/(wiki\/|w\/index\.php\?title=)([^&?#]*)/; ptitle = pagetitleRe.exec(decodeURI(location.href))[2].split('_').join(' '); // if this is a user, show the logs for the user rather than the page if( (window.location.href.indexOf("User:") != -1) || (window.location.href.indexOf("User_talk:") != -1) ) { regDropSubpages = /[User|User_talk]:([^&?\/]*)[\/]?.*/; user = regDropSubpages.exec(ptitle)[1]; url = "http://en.wikipedia.org/w/index.php?title=Special%3ALog&user=" + user; } else if(window.location.href.indexOf("Special:") != -1) { // don't display link for special pages return; } else { url = "http://en.wikipedia.org/w/index.php?title=Special%3ALog&page=" + ptitle; } tabs = document.getElementById('p-tb').getElementsByTagName('ul')[0]; l = addlilink(tabs, url, "Logs", "pt-logs"); }); /*</nowiki></pre> ===Google search=== From [[Wikipedia:WikiProject User scripts/Scripts/Google link]]. <pre><nowiki>*/ addOnloadHook(function () { // add onload handler using code from wikibits.js var title; if (!(title = document.getElementById('t-whatlinkshere') )) return; if (!(title = title.getElementsByTagName('a')[0] )) return; if (!(title = title.href )) return; if (!(title = title.replace(/^.*Special:Whatlinkshere\//, '') )) return; if (!(title = title.replace(/^(Talk|User|Wikipedia|Image|MediaWiki|Template|Help|Category|Portal)(_talk)?:/, '') )) return; if (!(title = title.replace(/("|%22)/g, '') )) return; if (!(title = title.replace(/_/g, '%20') )) return; addLink('p-tb', 'http://www.google.com/search?q=%22'+title+'%22%20-Wikipedia&ie=utf-8&oe=utf-8', 'Google search', 't-googlesearch', 'Search Google for "'+decodeURIComponent(title)+'"', 'G', null); // addLink('p-tb', 'http://search.yahoo.com/search?p=%22'+title+'%22%20-Wikipedia&ei=UTF-8', // 'Yahoo! search', 't-yahoosearch', 'Search Yahoo! for "'+decodeURIComponent(title)+'"', 'Y', null); addLink('p-tb', 'http://www.google.com/search?q=%22'+title+'%22%20site:wikipedia.org%20-site:en.wikipedia.org%20-site:nostalgia.wikipedia.org', 'Google interwiki', 't-interwikisearch', 'Search Google for interwiki articles on "'+decodeURIComponent(title)+'"', 'G', null); }); /*</nowiki></pre> ==Tabs== ===Purge=== From [[Wikipedia:WikiProject User scripts/Scripts/Add purge to tabs]]. <pre><nowiki>*/ addOnloadHook( function (){ var x = document.getElementById('ca-history'); if(!x) return; if(x.children) x = x.children[0].href; else x = x.childNodes[0].href; addLink("p-cactions", x.replace(/=history/, "=purge"), 'purge', 'ca-purge', 'Purge the internal cache for this page', 0); }); /*</nowiki></pre> ==Bottom== <pre><nowiki>*/ // </nowiki></pre>