User:Peoplelikeyou/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
mNo edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
//This script ([[User:ais523/highlightmyname.js]]) highlights all instances of the
//adapted from [[User:ais523/adminrights.js]]
//logged-in user's username on pages by giving them a bright red background. It only
//
//checks bodyContent, not titles or sidebars.
// This script highlights bluelinks to selected users' userpages or talkpages in bodyContent  


//<nowiki><pre>
var userlist=new Array();
function highlightmyname(n,p) //node, parent node
 
importScript('User:Peoplelikeyou/userlist.js');
 
//Highlighting script. Based on [[User:ais523/highlightmyname.js]].
 
function highlightusers_inner(n,h) //node, relevant hyperlink fragment
{
  if (n.nodeType!=1||n.tagName.toLowerCase()!="a") return 0; // not an anchor
  if (n.href.indexOf(wgScript+"?title="+h) == -1 &&
      n.href.indexOf(wgArticlePath.split("$1")[0]+h) == -1) return 0; // to the wrong target
  var u=n.href.split(h)[1];
  if(userlist[u.split("_").join("%20")]==1)
  {
    n.style.backgroundColor="#FACDD5";
  }
  return 1;
}
 
function highlightusers(n) //node
{
{
   while(n!=null)
   while(n!=null)
   {
   {
     if(n.nodeType==3) //text node
     if(highlightusers_inner(n,"User:")) n=n.nextSibling;
    {
    else if(highlightusers_inner(n,"User_talk:")) n=n.nextSibling;
      if(n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase())!=-1)
    else if(highlightusers_inner(n,"Special:Contributions:")) n=n.nextSibling;
      {
        var ix=n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase());
        var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
        var t2=document.createTextNode(n.data.substr(ix,mw.config.get('wgUserName').length));
        var t3=ix+mw.config.get('wgUserName').length==n.data.length?null:
          document.createTextNode(n.data.substr(ix+mw.config.get('wgUserName').length));
        var s1=document.createElement("SPAN");
        s1.style.backgroundColor="#FF0000";
        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 occurences in the new nodes
        n=s2.nextSibling;
      }
      else
        n=n.nextSibling;
    }
     else
     else
     {
     {
       if(n.firstChild!=null) highlightmyname(n.firstChild,n);
       if(n.firstChild!=null) highlightusers(n.firstChild);
       n=n.nextSibling;
       n=n.nextSibling;
     }
     }
   }
   }
}
}
 
 
addOnloadHook(function() {
$(function() {
  if(location.href.indexOf("?ais523")==-1&&location.href.indexOf("&ais523")==-1)
     highlightusers(document.getElementById('bodyContent'));
     highlightmyname(document.getElementById('bodyContent').firstChild,
                    document.getElementById('bodyContent'));
});
});
//</pre></nowiki>
//[[Category:Wikipedia scripts]]

Latest revision as of 01:07, 20 October 2023

//adapted from [[User:ais523/adminrights.js]]
//
// This script highlights bluelinks to selected users' userpages or talkpages in bodyContent 

var userlist=new Array();

importScript('User:Peoplelikeyou/userlist.js'); 

//Highlighting script. Based on [[User:ais523/highlightmyname.js]].

function highlightusers_inner(n,h) //node, relevant hyperlink fragment
{
  if (n.nodeType!=1||n.tagName.toLowerCase()!="a") return 0; // not an anchor
  if (n.href.indexOf(wgScript+"?title="+h) == -1 &&
      n.href.indexOf(wgArticlePath.split("$1")[0]+h) == -1) return 0; // to the wrong target
  var u=n.href.split(h)[1];
  if(userlist[u.split("_").join("%20")]==1)
  {
    n.style.backgroundColor="#FACDD5";
  }
  return 1;
}

function highlightusers(n) //node
{
  while(n!=null)
  {
    if(highlightusers_inner(n,"User:")) n=n.nextSibling;
    else if(highlightusers_inner(n,"User_talk:")) n=n.nextSibling;
    else if(highlightusers_inner(n,"Special:Contributions:")) n=n.nextSibling;
    else
    {
      if(n.firstChild!=null) highlightusers(n.firstChild);
      n=n.nextSibling;
    }
  }
}

$(function() {
    highlightusers(document.getElementById('bodyContent'));
});