User:Dschwen/ignore.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/* Since I expect this little function to be discovered sooner or later I'll better 
   add a little explanation. Does this qualify as passive aggressive? Maybe. But I'm 
   a voluntary contributor here and think I'm under no obligation to read every statement
   from every user. Some people are just the equivalent of a red cloth for me, and 
   everybody will benefit from me just ignoring those people. So if it hurts noone I believe
   it is ok for me to make my work here as pleasant as possible.
*/
function ignoreUsers()
{
 // get discussion paragraphs, ':' indented at DD, '*' indented are 'LI', unindented are 'P'
 var tags = { 'DD':0, 'LI':0, 'P':0 };
 var protect = { 'DL':0, 'UL':0 };
 
 for( tag in tags )
 {
  paragraphs = document.getElementsByTagName(tag);

  // loop over all paragraphs
  for( key in paragraphs )
  {
   // loop over all immediate child elements (avoids looking at response paragraphs)
   var children = paragraphs[key].childNodes;
   if( children )
   {
    for( var i = 0; i < children.length; i++ )
    {
     // does paragraph contain a link to a blacklisted userpage? (unless we are on the blacklisted users talkpage!)
     var hide = false;
     if( children[i].nodeType === 1 && 
         children[i].tagName === 'A' && 
         ( ( ignoreUserList[children[i].title] === true &&
             'User:' + wgTitle !== children[i].title ) || 
           ( (children[i].title in ignoreUserList) && 
             $(paragraphs[key]).html().indexOf(ignoreUserList[children[i].title])>=0  )  
             ) )
     {
      hide=true;
      break;
     }
    }

    // hide this paragraph?
    if( hide )
    {
     var i = 0;
     while( i < children.length )
     {
      if( children[i].nodeType === 1 && !(children[i].tagName in protect) || children[i].nodeType !== 1 )
      {
       paragraphs[key].removeChild(children[i]);
      }
      else
       i++;
     }
    }

   }//endif children 
  }//endfor paragraphs
 }//endfor tags
}
$(document).ready(ignoreUsers);