User:CBM/monobook.js
< User:CBM
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.
/** CMummert's monobook.js
*
* Features:
* Edit count via Interiot
* Add link to edit first section of an article like any other section
* Add "Block log" link to toolbox on any user or user talk page
* Replace "edit this page" tab text with "edit" to make space for tabs
* Bypass ISBN links to go straight to Amazon
* Add an "unwatch" link to each entry in the watchlist
* Sort the watchlist by namespace
*/
/* importScript('User:^demon/csd.js'); */
//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
importScript('User:Interiot/Tool2/code.js'); }
//AzaThoth's twinkle script
/*
importScript('User:AzaToth/twinkle.js');
TwinkleConfig = {
toolboxButtons: ["tw-prod", "tw-csd", "tw-csd-reason", "tw-rpp", "tw-since", "tw-sincemine","tw-lastdiff"],
userTalkPageMode : 'tab'
};
*/
/* Enable cleanup tab if appropriate */
$(function() {
addOnloadHook(shortenEdit);
addOnloadHook(addTools);
});
/* This will add an [edit] link for the first section
* of all pages except preview pages and the main page
* by User:Pile0nades
*/
// Add an [edit] link to pages
$(function () {
// if this is preview page or generated page, stop
if(
document.getElementById("wikiPreview") ||
document.getElementById("histlegend") ||
document.getElementById("difference") ||
document.getElementById("watchdetails") ||
document.getElementById("ca-viewsource") ||
window.location.href.indexOf("/wiki/Special:") != -1
) {
if(window.location.href.indexOf("&action=edit§ion=0") != -1) {
document.getElementById("wpSummary").value = "/* [[en:WP:LEAD|Lede]] */ ";
}
return;
};
// get the page title
var pageTitle = wgPageName;
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsection">[<a href="/w/index.php?title='+pageTitle+'&action=edit§ion=0" title="Edit section: '+pageTitle+'">edit lede</a>]</div>';
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
});
/* Add link to toolbar for block log */
function addContribs(username) {
addTool("http://en.wikipedia.org/w/index.php?title=Special:Log&type=block&page=" + username, "Block log", "Foo3", "Foo4", "Foo5");
}
function addTools() {
addPersonal("http://en.wikipedia.org/wiki/User:CMummert/Templates", "Tools", "Tools3", "Tools4", "Tools5");
}
$(function() {
if (document.title.indexOf("User:") != -1 )
{
var UNindex = document.title.indexOf("- Wikipedia, the free encyclopedia");
var username = document.title.substring(0,UNindex);
if ( username.indexOf("/") != -1)
{ username = username.substring(0,username.indexOf("/")); }
addOnloadHook(addContribs(username));}
if (document.title.indexOf("User talk:") != -1 )
{
var UNindex = document.title.indexOf("- Wikipedia, the free encyclopedia");
var username = "User:" + document.title.substring(10,UNindex);
if ( username.indexOf("/") != -1)
{ username = username.substring(0,username.indexOf("/")); }
addOnloadHook(addContribs(username));}
});
function shortenEdit() {
var tab = document.getElementById('ca-edit');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-edit').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("edit"), tab.firstChild);
tab = document.getElementById('ca-talk').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("talk"), tab.firstChild);
}
var tab = document.getElementById('ca-history');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-history').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("hist"), tab.firstChild);
}
/*
var tab = document.getElementById('ca-protect');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-protect').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("prot"), tab.firstChild);
}
*/
var tab = document.getElementById('ca-edit');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-edit').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("edit"), tab.firstChild);
}
/*
var tab = document.getElementById('ca-delete');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-delete').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("rm"), tab.firstChild);
}
*/
var tab = document.getElementById('ca-move');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-move').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("mv"), tab.firstChild);
}
}
/* Add link to toolbox*/
function addTool(url, name, id, title, key){
var tabs = document.getElementById('p-tb').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add Tab */
function addTab(url, name, id, title, key){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add Personal */
function addPersonal(url, name, id, title, key){
var tabs = document.getElementById('p-personal').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add LI to a UL */
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;
}
/* Bypass ISBN page to go straight to amazon */
function externISBN() {
for (var i = 0; i < document.links.length; i++)
{
if( document.links[i].href.match(/isbn=(.*)/) ) {
document.links[i].href='http://www.amazon.com/gp/search/ref=sr_adv_b/?search-alias=stripbooks&field-isbn='+RegExp.$1;
}
}
}
$(externISBN);
/* add unwatch links to watchlist */
$(function () {
// Check if we're on the watchlist
if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist")
return;
if (!document.forms[0] || !document.forms[0].namespace) return;
// Unwatch links go back to watchlist with "Removing requested items
// from watchlist..." message
// var query_prefix = "title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=submit&remove=1&id[]=";
// ...or...
// Unwatch links go to "Removed from watchlist" page
var query_prefix = "action=unwatch&title=";
// get list of all links in content:
var links = document.getElementById('content').getElementsByTagName('a');
// make a static copy of the nodelist and lose the original for speed
// while we're at it, prune the uninteresting links from the list
var linksCopy = new Array ();
for (var i = 0; i < links.length; i++) {
if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
}
links = linksCopy;
for (var i = 0; i < links.length; i++) {
// create unwatch link and append it after history link
var unwatch = document.createElement('a');
unwatch.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
unwatch.title = "Unwatch "+links[i].title;
unwatch.appendChild(document.createTextNode("unwatch"));
links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
// insert a delimiter between the two links
var delim = links[i].previousSibling;
delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
links[i].parentNode.insertBefore(delim, unwatch);
}
});
//
// WATCHLIST SORTER
// Taken from User:Misza13 and edited by me to work with unwatch links
// Also fixed sorting of namespaces and made the ul's have class=special
function addNamespaceWL(newday, namespace) {
hdr = document.createElement('h5');
hdr.innerHTML = namespace;
newday.appendChild(hdr);
namespacesub = document.createElement('ul');
namespacesub.setAttribute("class", "special");
newday.appendChild(namespacesub);
return hdr;
}
$(function (){
if (location.href.indexOf('Special:Watchlist') == -1) return; //Are we on a watchlist?
//days = document.getElementById('bodyContent').getElementsByTagName('ul');
//Hell knows how it works - found in "Dive into Greasemonkey"
// - from original coder
days = document.evaluate( "//ul[@class='special']", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (d = 0; d < days.snapshotLength; d++) {
//For each day
day = days.snapshotItem(d);
newday = document.createElement('div'); //This will replace the old listing
//add the main namespaces in order so they are sorted correctly
//additional namespaces will be created at the bottom when they are encountered
//change the order here to whatever you like
addNamespaceWL(newday, "Main");
addNamespaceWL(newday, "Talk");
addNamespaceWL(newday, "Wikipedia talk");
addNamespaceWL(newday, "User talk");
addNamespaceWL(newday, "User");
while ((diffs = day.getElementsByTagName('li')).length > 0) {
//Are there any diffs left?
//Try to extract the namespace
As = diffs[0].getElementsByTagName('a');
// if you don't have the unwatch links, replace As[3] with As[2], etc.
if (As[0].innerHTML == 'diff') {
pagename = As[3].innerHTML;
} else {
pagename = As[2].innerHTML;
}
if (pagename.indexOf(':') == -1)
namespace = 'Main';
else
namespace = pagename.split(':')[0];
//This will fail for articles which contain ":" in name
hdrs = newday.getElementsByTagName('h5'); //Get the list of namespace headers
hdr = null;
for (j=0; j<hdrs.length; j++) //Find the header
if (hdrs[j].innerHTML==namespace) {
hdr = hdrs[j]; break;
}
if (hdr==null) { //Not found? Make a new one!
hdr = addNamespaceWL(newday, namespace);
}
hdr.nextSibling.appendChild(diffs[0]); //Move the diff
}
newday.appendChild(document.createElement('hr')); //For readablility
day.parentNode.replaceChild(newday,day);
}
});
// Edit counter
// Script from [[User:ais523/editcount.js]]
// importScript('User:ais523/editcount.js'); //[[User:ais523/editcount.js]]
//