User:Daichinger/monobook.js

// Add date and time to your monobook "personal menu" list at the very top of the page. // Created by User:Mathwiz2020

// Indicate where you would like the time to appear: // 1 is first (before username), 2 is second (before talk link), ... 7 is last (after log out link) insertBeforeNum = 7;

// Do NOT edit below this line unless you're experiened in javascript insertBeforeArr = new Array("","pt-userpage","pt-mytalk","pt-preferences","pt-watchlist","pt-mycontris","pt-logout",""); insertBefore = insertBeforeArr[insertBeforeNum];

function makeTime { var li = document.createElement( 'li' ); li.id = 'pt-time';

var mySpan = document.createElement( 'span' ); mySpan.appendChild( document.createTextNode( 'date and time' ) );

li.appendChild( mySpan );

if ( insertBefore ) {   var before = document.getElementById( insertBefore ); before.appendChild( li, before ); } else // append to end (right) of list {   document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); }

getTime; }

if     ( window.addEventListener ) window.addEventListener ( 'load', makeTime, false ); else if ( window.attachEvent     ) window.attachEvent      ( 'onload', makeTime      );

function getTime {   var time    = new Date; var date   = time.getUTCDate; var months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '); month  = months[time.getUTCMonth]; var year   = time.getUTCFullYear; var hours  = '0' + time.getUTCHours; hours  = hours.substr(hours.length-2, hours.length); var minutes = '0' + time.getUTCMinutes; minutes = minutes.substr(minutes.length-2, minutes.length); var seconds = '0' + time.getUTCSeconds; seconds = seconds.substr(seconds.length-2, seconds.length); var curTime = hours + ":" + minutes + ":" + seconds + ", " + date + " " + month + " " + year + " (UTC)"; datePlace  = document.getElementById('pt-time').childNodes[0].childNodes[0]; datePlace.replaceData(0, datePlace.length, curTime); doTime     = window.setTimeout("getTime", 1000); } addOnloadHook ( extendededitlinks ) ; function extendededitlinks_get_event_target ( e ) { var targ ; if (!e) var e = window.event; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug while ( targ.nodeType != 1 || targ.className != "editsection" ) targ = targ.parentNode ; return targ ; } function extendededitlinks_is_relevant_heading ( current, compare ) { if ( current.nodeType != 1 ) return false ; if ( current.tagName.length != 2 ) return false ; if ( current.tagName.substr ( 0, 1 ) != "H" ) return false ; if ( current.tagName> compare.tagName) return false ; return true ; } function extendededitlinks_onmouseover ( e ) { var target = extendededitlinks_get_event_target ( e ) ; var h2 = target ; while ( h2.nodeType != 1 || h2.tagName.substr(0,1) != "H" ) h2 = h2.parentNode; var newdiv = document.createElement ( "div" ) ; newdiv.style.backgroundColor = "#DDDDDD" ; // newdiv.style.border = "1px solid black" ; // newdiv.style.padding = "2px" ; h2.parentNode.insertBefore ( newdiv, h2 ) ; newdiv = h2.previousSibling ; // Unneccessary? var x = h2 ; do { var y = x ; x = x.nextSibling ; newdiv.appendChild ( y ) ; } while ( x && !extendededitlinks_is_relevant_heading ( x, h2 ) ) ; } function extendededitlinks_onmouseout ( e ) { var target = extendededitlinks_get_event_target ( e ) ; var h2 = target ; while ( h2.nodeType != 1 || h2.tagName.substr(0,1) != "H" ) h2 = h2.parentNode; var newdiv = h2 ; while ( newdiv.nodeType != 1 || newdiv.tagName != "DIV" ) newdiv = newdiv.parentNode; for ( var y = newdiv.firstChild ; y ; y = z ) { z = y.nextSibling ; newdiv.parentNode.insertBefore ( y, newdiv ) ; } newdiv.parentNode.removeChild ( newdiv ) ; } function extendededitlinks { var spans = document.getElementsByTagName( "span" ); for ( var i = 0 ; i < spans.length ; i++ ) { if ( spans[i].className != "editsection" ) continue ; var a = spans[i].getElementsByTagName("a")[0] ; a.onmouseover = extendededitlinks_onmouseover ; a.onmouseout = extendededitlinks_onmouseout ; } } //note: this script MUST be added to the end of your monobook at all times. //so when you add a new script to the end of your monobook, re-order them so this one is on the bottom. addOnloadHook(function {       if(!document.getElementById('wpSummary') || document.getElementById('wpSummary').value != '' || !document.getElementById('wpTextbox1')) return;        var my_value;        if(wgCanonicalNamespace == 'User_talk') {                if(wgPageName.indexOf('/') == -1 && wgTitle.split('/')[0] != wgUserName)                         my_value = 'Respond to '+wgTitle;                else if(wgPageName.indexOf('archive') != -1 && wgTitle.split('/')[0] != wgUserName)                         my_value = 'Reviving archive';                else if(wgPageName.indexOf('archive') != -1 && wgTitle.split('/')[0] == wgUserName)                        my_value = 'Archiving...';                else if(wgPageName.indexOf('/') == -1 && wgTitle.split('/')[0] == wgUserName)                         my_value = 'Reply';                else                        my_value = 'minor edit'; } else if(wgCanonicalNamespace == 'User') { if(wgTitle.split('/')[0] == wgUserName) my_value = 'fixing'; else my_value = 'fixing a minor mistake'; //note: leave as "Project". thats how mediawiki outputs it       } else if(wgCanonicalNamespace == 'Project'||wgCanonicalNamespace == 'Project_talk') { if((/\w+ for deletion/i).test(wgTitle)) my_value = 'Add my opinion'; else if((/requests for adminship/i).test(wgTitle)) my_value = 'Support'; else if((/administrator.s noticeboard/i).test(wgTitle)) my_value = 'Reply'; else if((/administrator intervention against vandalism/i).test(wgTitle)) my_value = 'Reporting user'; else my_value = 'Reply'; } else { my_value = 'minor edit'; }       document.getElementById('wpSummary').value = my_value; document.getElementById('wpSummary').onfocus = function { if(this.value != my_value) return; this.selectionStart = 0; this.selectionEnd = this.value.length; } });