User:Nickptar/monobook.js

//////// edittop /////////// if ((wgAction == 'view' || wgAction == 'purge') && wgNamespaceNumber >=0) addOnloadHook(function edittop_hook{ var localtitles = {  en: 'Edit lead section',   fr: 'Modifier le résumé introductif',   it: 'Modifica della sezione iniziale',   ja: '導入部を編集' }; var h2s = document.getElementsByTagName('H2'); var h2 = h2s[0]; if (!h2) return; if (h2.parentNode.id == 'toctitle') h2 = h2s[1]; if (!h2) return; var span = h2.firstChild; if (!span || span.className != 'editsection') return; var zero = span.cloneNode(true); if (document.getElementById('featured-star')) zero.style.marginRight = '25px'; if (document.getElementById('spoken-icon')) zero.style.marginRight = '45px'; if (document.getElementById('protected-icon') && zero.style.marginRight) zero.style.marginRight = '70px'; var parent = document.getElementsByTagName('H1')[0]; parent.insertBefore(zero, parent.firstChild); var a = zero.getElementsByTagName('A')[0]; if(localtitles[wgUserLanguage]) a.title = localtitles[wgUserLanguage]; // TODO check for content of header, to get a more precise replacement else a.title = a.title.replace(/:.*$/,': 0'); a.setAttribute('href', a.href.replace(/&section=1/,'&section=0')); });

//////////// UTCLiveClock ///////////// function liveClock {	liveClock.node = addPortletLink( 'p-personal', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=purge', '', 'utcdate' ); liveClock.node.style.fontWeight = 'bolder'; showTime; } function showTime {	var dateNode = liveClock.node; if( !dateNode ) { return; }   var now = new Date; var hh = now.getUTCHours; var mm = now.getUTCMinutes; var ss = now.getUTCSeconds; var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss ); dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild ); window.setTimeout(showTime, 1000); }

//////// mine ///////////

addOnloadHook(function {

liveClock;

addPortletLink('p-personal', 'http://en.wikipedia.org/w/index.php?title=Special:Log&user=Nickptar', 'my logs', 'pt-logs', 'My logs', 'g', document.getElementById('pt-logout'));

if (document.location.href.indexOf('Special:Contributions') != -1) { if (document.getElementById('contentSub').textContent.indexOf("For Nickptar ") != -1) { var linkp = document.getElementById('bodyContent').firstChild; while (linkp.tagName == null || linkp.tagName.toLowerCase != 'p') linkp = linkp.nextSibling; linkp.innerHTML += " (hide top)";

top_contribs = []; var ul = linkp; while (ul.tagName == null || ul.tagName.toLowerCase != 'ul') ul = ul.nextSibling; for (var i = 0; i < ul.childNodes.length; i++) { var child = ul.childNodes[i]; if (child.textContent != null && child.textContent.indexOf(" (top)") != -1) top_contribs.push(child); } } }

/////////// addsection-plus ///////////// var tab = document.getElementById('ca-addsection'); if(!tab) return; var tablink = tab.getElementsByTagName('a')[0]; if(!tablink) return; tablink.firstChild.nodeValue = '+'; tablink.style.paddingLeft = ".4em"; tablink.style.paddingRight = ".4em"; });

function top_vis(visible) { for (var i = 0; i < top_contribs.length; i++) top_contribs[i].style.display = visible ? '' : 'none';

var link = document.getElementById('a-hide-show-top'); link.href = "javascript:top_vis(" + !visible + ")"; link.textContent = (visible ? "hide" : "show") + " top"; }

/////////// contribsrange //////////// if(wgCanonicalSpecialPageName == 'Contributions') { addOnloadHook(prefixContribsInit); var prefixlimit = 500; var frm = ''; //global } function prefixContribsInit { var show = (document.getElementById('contentSub')) ? document.getElementById('contentSub') : document.getElementById('topbar') show.appendChild(document.createTextNode(' \u2022 Javascript-enhanced contributions lookup enabled. You may enter a CIDR range or append an asterisk to do a prefix search.')) frm = document.getElementsByTagName('form')[0]; if(!frm.target) return; //general optionlets independant of type of search. var opt_ns = (parseInt(frm.namespace[frm.namespace.selectedIndex].value) > -1) ? '&ucnamespace=' + frm.namespace[frm.namespace.selectedIndex].value : ''; var opt_ts = ''; if(queryString('ucstart')) { opt_ts = '&ucstart=' + queryString('ucstart'); } else { var m = '' + frm.month.selectedIndex; var y = frm.year.value; if(m.length == 1) m = '0' + m   if(y > 2000 && y < 2100) opt_ts = '&ucstart=' + y + '-' + m + '-01T00:00:00Z' } var options = opt_ns + opt_ts; var patternCIDR = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(2[4-9]|3[0-2]|16)/i ; var patternWild = /^.{3,}\*$/i ; if(frm.target.value.search(patternCIDR) == 0) { prefixContribsStartbox(frm.parentNode); var cidr = frm.target.value.match(patternCIDR)[0]; var range = cidr.match(/[^\/]\d{1,2}$/i)[0]; if(range == 24 || range == 16) { //prefixable CIDR, lets do-er if(range == 24) { cidr = cidr.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\./)[0]; } else { cidr = cidr.match(/\d{1,3}\.\d{1,3}\./)[0]; }     var url = wgScriptPath + '/api.php?action=query&format=json&rawcontinue=&callback=prefixContribs&list=usercontribs' + options + '&uclimit=' + parseInt(prefixlimit) + '&ucuserprefix=' + cidr; prefixContribsCall(url); } else { //complex CIDR, lets figure it out var oct3 = cidr.match(/\.\d{1,3}\//i)[0].replace(/(\.|\/)/g,''); cidr = cidr.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\./)[0]; var num = Math.pow(2,32 - range); var start = oct3 - oct3 % num; var url = wgScriptPath + '/api.php?action=query&format=json&callback=prefixContribs&list=usercontribs' + options + '&uclimit=' + parseInt(prefixlimit) + '&ucuser='; for(var i=start;i<=start + num;i++) { url += '' + cidr + i;       if(i != start + num) url += '|' }     prefixContribsCall(url); } } else if(frm.target.value.search(patternWild) == 0) { //very simple wildcard, lets do-er prefixContribsStartbox(frm.parentNode); var prefix = frm.target.value.replace(/\*$/,''); prefix = prefix.substr(0,1).toUpperCase + prefix.substr(1); var url = wgScriptPath + '/api.php?action=query&format=json&callback=prefixContribs&list=usercontribs' + options + '&uclimit=' + parseInt(prefixlimit) + '&ucuserprefix=' + prefix; prefixContribsCall(url); } } function prefixContribsStartbox(parent) { var res = document.createElement('div'); res.setAttribute('id','results-from-CIDR'); res.style.border = '1px solid black'; res.style.padding = '.5em'; var prog = document.createElement('img'); prog.setAttribute('id','prefixcontribs-prog'); prog.setAttribute('src',stylepath + '/common/images/spinner.gif'); res.appendChild(prog); parent.appendChild(res); } function prefixContribsCall(url) { var scriptElem = document.createElement('script'); scriptElem.setAttribute('src',url); scriptElem.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(scriptElem); } function prefixContribs(obj) { if(!obj['query'] || !obj['query']['usercontribs']) return var prog = document.getElementById('prefixcontribs-prog'); if(prog) prog.parentNode.removeChild(prog) cidr = obj['query']['usercontribs']; var res = document.getElementById('results-from-CIDR'); res.appendChild(document.createElement('hr')); if(cidr.length == 0) { res.appendChild(document.createTextNode('No changes were found for this wildcard/CIDR range.')); res.appendChild(document.createElement('hr')); return; } res.appendChild(document.createTextNode(cidr.length + ' matches in the wildcard/CIDR range specified (chronologically): ')); if(cidr.length == parseInt(prefixlimit)) { res.appendChild(document.createElement('br')); res.appendChild(document.createTextNode('Click ')); var ns = (parseInt(frm.namespace[frm.namespace.selectedIndex].value) > -1) ? '&namespace=' + frm.namespace[frm.namespace.selectedIndex].value : ''; var ts = (obj['query-continue']) ? obj['query-continue'].usercontribs.ucstart : cidr[cidr.length-1].timestamp; addlinkchild(res, wgScript + '?title=Special:Contributions&target=' + encodeURIComponent(frm.target.value) + ns + '&ucstart=' + ts, 'here'); res.appendChild(document.createTextNode(' to see the next ' + prefixlimit + ' results.')); } res.appendChild(document.createElement('hr')); for(var i=0;i<cidr.length;i++) { res.appendChild(document.createTextNode('\u2022 ' + cidr[i].timestamp.replace(/T[\d:]*Z/,' '))); addlinkchild(res, wgScript + '?title=Special:Contributions/' + cidr[i].user, cidr[i].user); res.appendChild(document.createTextNode(' edited ('));   addlinkchild(res, wgScript + '?title=-&curid=' + cidr[i].pageid + '&diff=' + cidr[i].revid, 'diff');    res.appendChild(document.createTextNode(') ')); addlinkchild(res, wgScript + '?title=-&curid=' + cidr[i].pageid, cidr[i].title); if(cidr[i].comment) res.appendChild(document.createTextNode(' (' + cidr[i].comment + ')')); res.appendChild(document.createElement('br')); } } function addlinkchild(obj,href,text,id,classes) { if(!obj || !href || !text) return false; var a = document.createElement('a'); a.setAttribute('href',href); a.appendChild(document.createTextNode(text)); if(id) a.setAttribute('id',id); if(classes) a.setAttribute('class',classes); obj.appendChild(a); } function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }