Jump to content

User:Sarregouset/monobook.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Sarregouset (talk | contribs)
m SKYY's Dark Wikipedia
Sarregouset (talk | contribs)
i don't really use these, so hopefully
Line 1: Line 1:
//This script highlights all instances of the logged-in user's username on pages
//by giving them a blue background. It only checks bodyContent, not titles or sidebars.
function highlightmyname(n,p) //node, parent node
{
while(n!=null)
{
if(n.nodeType==3) //text node
{
if(n.data.toLowerCase().indexOf(wgUserName.toLowerCase())!=-1)
{
var ix=n.data.toLowerCase().indexOf(wgUserName.toLowerCase());
var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
var t2=document.createTextNode(n.data.substr(ix,wgUserName.length));
var t3=ix+wgUserName.length==n.data.length?null:
document.createTextNode(n.data.substr(ix+wgUserName.length));
var s1=document.createElement("SPAN");
s1.style.backgroundColor="#787878";
s1.appendChild(t2);
var s2=document.createElement("SPAN");
if(t1!=null) s2.appendChild(t1);
s2.appendChild(s1);
if(t3!=null) s2.appendChild(t3);
p.replaceChild(s2,n);
if(t3!=null) highlightmyname(t3,s2); //find remaining occurrences in the new nodes
n=s2.nextSibling;
}
else
n=n.nextSibling;
}
else
{
if(n.firstChild!=null) highlightmyname(n.firstChild,n);
n=n.nextSibling;
}
}
}
addOnloadHook(function() {
if(location.href.indexOf("?ais523")==-1&&location.href.indexOf("&ais523")==-1)
highlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'));
});



//This code adds an 'unwatch' link to each item on watchlist.
addOnloadHook(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(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 = wgServer + 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);
}
});



// Add 'purge' tab to clear Wikipedia's cache of the page.
// Add 'purge' tab to clear Wikipedia's cache of the page.
addOnloadHook(function () {
addOnloadHook(function () {
Line 156: Line 68:
caMove.style.marginRight = '0.3em';
caMove.style.marginRight = '0.3em';
})
})



// Add date and time to your monobook "personal menu" list at the very top of the page.
// Indicate where you would like the time to appear:
// 1 is first (after username), 2 is second (after talk link), ... 6 is last (after log out link)
insertBeforeNum = 6;
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 + ", " + month + " " + date + ", " + year;
datePlace = document.getElementById('pt-time').childNodes[0].childNodes[0];
datePlace.replaceData(0, datePlace.length, curTime);
doTime = window.setTimeout("getTime()", 1000);
}





// [[Wikipedia:Tools/Navigation popups]]
// [[Wikipedia:Tools/Navigation popups]]
importScript('User:Lupin/popups.js');
importScript('User:Lupin/popups.js');


// http://brianna.modernthings.org/article/184/media-handling-on-wikimedia-preview-the-future-part-1
importScriptURI('http://mvbox2.cse.ucsc.edu/enwiki/w/extensions/MetavidWiki/skins/add_media_wizard.js');

Revision as of 23:23, 14 July 2010

// Add 'purge' tab to clear Wikipedia's cache of the page.
addOnloadHook(function () {
    var hist, url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                   'purge', 'ca-purge', 'Purge server cache for this page', 'alt-p');
});



// Add 'diff' tab to see the most recent change to this page.
if (wgNamespaceNumber >= 0)
addOnloadHook(function () {
    addPortletLink('p-cactions', 'http://en.wikipedia.org/enwiki/w/index.php?title=' + wgPageName + '&diff=cur', 'diff', 'ca-last', 'See the most recent change to this page', 'alt-v');
});



//Adds extra edit, history, and diff tabs so from any page you can jump to both main page and talk page.
if (wgNamespaceNumber >= 0)
addOnloadHook(function()
{
 var pCactions = document.getElementById('p-cactions');
  if (!pCactions) return;
 var caMain = pCactions.getElementsByTagName('li')[0]; 
 var caTalk = document.getElementById('ca-talk');
 var caEdit = document.getElementById('ca-edit');
 var caMove = document.getElementById('ca-move');
 var caLast = document.getElementById('ca-last');
  if (!caEdit) caEdit = document.getElementById('ca-viewsource');
 var caHistory = document.getElementById('ca-history');
 if (!caMain || !caTalk || !caEdit || !caHistory) return; 
 var el_move, el_create, id2;
  if (wgNamespaceNumber % 2) //talk space
  {                     
   el_move = caTalk;
   el_create = caMain;
   id2 = '';
  } 
  else {
   el_move = caMain;
   el_create = caTalk;
   id2 = 'discussion';
  }
 caEdit.firstChild.innerHTML = 'edit';
 caHistory.firstChild.innerHTML = 'history';
 caTalk.firstChild.innerHTML = 'talk';
 caMove.firstChild.innerHTML = 'move';
 el_move.parentNode.insertBefore(caLast, el_move.nextSibling);
 el_move.parentNode.insertBefore(caHistory, el_move.nextSibling);
 el_move.parentNode.insertBefore(caEdit, el_move.nextSibling);
 var href = el_create.firstChild.getAttribute('href', 2);
 if (el_create.className.indexOf('new') < 0)
 {
   addPortletLink('p-cactions', href + '?diff=cur', 'diff',
     'ca-last-'+id2, 'View the last change', '', el_create.nextSibling);
   addPortletLink('p-cactions', href + '?action=history', 'history',
     'ca-history-'+id2, 'Past versions of this page', '', el_create.nextSibling);
   addPortletLink('p-cactions', href + '?action=edit', 'edit',
     'ca-edit-'+id2, 'You can edit this page', '', el_create.nextSibling);
 } 
 caMain.style.marginRight = '0.3em';
 caTalk.style.marginRight = '0.3em';
 caTalk.style.marginLeft  = '1.6em';
 caMove.style.marginLeft  = '1.6em';
 caMove.style.marginRight = '0.3em';
})


// [[Wikipedia:Tools/Navigation popups]]
importScript('User:Lupin/popups.js');