User:Mxn/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.
/* [[Wikipedia:WikiProject User scripts/Scripts/addLink|addLink]] */ 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", or "p-navigation". //* 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; } /* [[Wikipedia:WikiProject User scripts/Scripts/Add purge to tabs|addPurge]] */ function AddPurge () { 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); } addOnloadHook(AddPurge); /* [[Wikipedia:WikiProject User scripts/Scripts/Fix diff width|Fix diff width]] */ function FixDiffWidth() { var diffSigns = new Array(); var fixDiffWidth = function () { var tables = document.getElementsByTagName('table'); for (var i = 0; i < tables.length; i++) if (tables[i].className == 'diff') { var rows = tables[i].getElementsByTagName('tr'); var diffDiv = document.createElement('div'); diffDiv.style.backgroundColor = 'white'; diffDiv.className = 'xdiff'; for (var j = 0; j < rows.length; j++) { var rowDiv = document.createElement('div'); rowDiv.style.width = '100%'; rowDiv.style.margin = '0 0 3px 0'; rowDiv.style.overflow = 'hidden'; // trick, makes it expand vertically to contain floats rowDiv.className = 'xdiff-row'; var colDiv = null; var cols = rows[j].getElementsByTagName('td'); for (var k = 0; k < cols.length; k++) { if (!colDiv) { colDiv = document.createElement('div'); colDiv.style.cssFloat = 'left'; colDiv.style.clear = 'none'; colDiv.style.position = 'relative'; colDiv.style.width = '49%'; colDiv.className = 'xdiff-col'; rowDiv.appendChild(colDiv); } var innerDiv = document.createElement('div'); if (cols[k].getAttribute('colspan') == 2 || cols[k].className.substring(0,5) == 'diff-') { innerDiv.style.overflow = 'auto'; // scroll if necessary! innerDiv.style.padding = '1px'; if (cols[k].getAttribute('colspan') != 2) { innerDiv.style.margin = '0 0 0 2em'; innerDiv.style.fontSize = '85%'; // from MediaWiki:Monobook.css if (cols[k].className == 'diff-addedline') innerDiv.style.backgroundColor = '#cfc'; if (cols[k].className == 'diff-deletedline') innerDiv.style.backgroundColor = '#ffa'; if (cols[k].className == 'diff-context') innerDiv.style.backgroundColor = '#eee'; } innerDiv.style.textAlign = cols[k].getAttribute('align'); innerDiv.className = (cols[k].className ? "x"+cols[k].className : ""); } else if (cols[k].firstChild && (cols[k].firstChild.nextSibling || cols[k].firstChild.nodeType != 3 || cols[k].firstChild.nodeValue.match(/\S/))) { innerDiv.style.width = '2em'; innerDiv.style.textAlign = 'center'; innerDiv.style.position = 'absolute'; innerDiv.className = 'xdiff-sign'; diffSigns.push(innerDiv); } else continue; for (var node = cols[k].firstChild; node; node = node.nextSibling) innerDiv.appendChild(node.cloneNode(true)); innerDiv.appendChild(document.createTextNode(String.fromCharCode(0xa0))); // add nbsp colDiv.appendChild(innerDiv); if (innerDiv.className != 'xdiff-sign') colDiv = null; // start new columns } // force rowDiv to expand, just in case position trick fails var clearer = document.createElement('span'); clearer.clear = 'left'; rowDiv.appendChild(clearer); diffDiv.appendChild(rowDiv); } tables[i].parentNode.replaceChild(diffDiv, tables[i]); } }; // finally, a kluge to vertically center the +/- signs var centerDiffSigns = function () { for (var i = 0; i < diffSigns.length; i++) { var parentHeight; if (!( parentHeight = diffSigns[i].parentNode )) continue; if (!( parentHeight = parentHeight.clientHeight )) continue; diffSigns[i].style.top = Math.round((parentHeight - diffSigns[i].offsetHeight)/2) + "px"; } }; fixDiffWidth(); hookEvent('resize', centerDiffSigns); setTimeout(centerDiffSigns, 250); } if (window.addEventListener) addOnloadHook(FixDiffWidth); /* [[User:Cacycle/wikEd]] */ /* // install [[User:Cacycle/diff]] text diff code document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); // install [[User:Pilaf/Live Preview]] page preview tool document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); // install [[User:Cacycle/editor]] edit tool document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); */