MediaWiki:Gadget-resaltador.js
Nota: Después de guardar, debes recargar la caché de tu navegador para ver los cambios:
- Mozilla: Pulsa Recargar (o Ctrl-R)
- Internet Explorer / Opera: Ctrl-F5
- Safari: Cmd-R
- Konqueror Ctrl-R.
//This script ([[w:User:ais523/highlightmyname.js]]) highlights all instances of the
//logged-in user's username on pages by giving them a grey background. It only
//checks bodyContent, not titles or sidebars.
//<nowiki><pre>
function highlightmyname(n,p,u) //node, parent node, user
{
while(n!==null)
{
if(n.nodeType===3) //text node
{
if(n.data.toLowerCase().indexOf(u.toLowerCase())!=-1)
{
var ix=n.data.toLowerCase().indexOf(u.toLowerCase());
var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
var t2=document.createTextNode(n.data.substr(ix,u.length));
var t3=ix+u.length==n.data.length?null:
document.createTextNode(n.data.substr(ix+u.length));
var s1=document.createElement("SPAN");
s1.style.backgroundColor="#D8D8D8";
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, u); //find remaining occurences in the new nodes
n=s2.nextSibling;
}
else
n=n.nextSibling;
}
else
{
if(n.firstChild!==null) highlightmyname(n.firstChild,n, u);
n=n.nextSibling;
}
}
}
$(function() {
if(location.href.indexOf("?ais523")==-1&&location.href.indexOf("&ais523")==-1&&
location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&&
location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&&
location.href.indexOf("&action=raw")==-1&&mw.config.get('wgPageName')!="Special:Preferences")
highlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'), mw.config.get('wgUserName'));
});