relax

Author Topic: ignore user feature for Firefox  (Read 4852 times)

Offline Harlan

  • Governor
  • ***********
  • Posts: 2102
  • Gender: Male
  • Lemon Pistachios
    • Photos...
ignore user feature for Firefox
« on: December 31, 2007, 05:05:18 PM »
Hi, periodically over the last few years, people (including myself) have asked for an "ignore user" feature for the board. While our esteemed leader and moderators haven't agreed to add such a feature, it is possible to fake it using a client-side script. (Server = Merm's computer, Client = Your computer.) This script, which I found on the net and then fixed, seems to work relatively well. Importantly, however, it only works for people running the Firefox web browser and the Greasemonkey extension. (Greasemonkey allows you to install scripts that over-ride the way web pages display. Pretty cool.) Here's how to install it:

  • Make sure you're running Firefox 2.0 or later.
  • Install the Greasemonkey extension. Restart Firefox. Note the cute little monkey in the lower-right corner.
  • Copy the script below into Notepad, and save it as a file, on your Desktop, say, called smfuserhide.user.js (yes, with two dots).
  • In Firefox, do a File, Open File..., and open the .js file. You'll be prompted to install the script. Say Install.
  • Test it! There should now be a little
  • next to everyone's name in a thread. To hide them, click the
  • and refresh the page.

Let me know if you can't get it to work! I'm no guru at this stuff, but I might be able to figure simple problems out...

OK, here it is... (crossing fingers...!)

Code: [Select]
// ==UserScript==
// @name          SMF User Hide
// @include       *astorians*/index.php?topic=*
// @description   hides / unhides a user's posts - based on User Classes by Unarmed, and tweaked/debugged by Harlan
// @exclude
// ==/UserScript==

(function() {
   // Get stored hidden users from cookie
   var users = [];
   var cookieName = "smfUserHide";
   for (var i = 0; i < document.cookie.split('; ').length; i++) {
      var oneCookie = document.cookie.split('; ')[i].split('=');
      if (oneCookie[0] == cookieName) {
         users = oneCookie[1].split(', ');
         break;
      }
   }
//GM_log(users);

   // Find all the usernames in the page
   var results = document.evaluate("//td/b/a[starts-with(@title, 'View the profile of')]", document, null,
      XPathResult.ANY_TYPE, null);
   var resultNodes = [];
   var aResult;
   while (aResult = results.iterateNext())
      resultNodes.push(aResult);

   // Loop through every user post on the page
   for (var i in resultNodes) {
//GM_log('looping through posts');

      var containingRow = resultNodes[i].parentNode.parentNode.parentNode;
      // Format whitespace
      var user = encodeURI(resultNodes[i].innerHTML);
//GM_log(user);

      // Flag whether the user is in our hide list
      var notFound = true;
      for (var j = 0; j < users.length; j++) {
//GM_log(users[j]);
         if (users[j] == user) {
            notFound = false;
//GM_log('user found!');
         }
      }

      // Add relevant event handlers to a "[X]" node in front of user's name
      // On click, add or remove this user from the stored user list in the cookie
      var toggler = document.createElement('span');
      toggler.title = "click to add or remove this user from your hide list";
      toggler.appendChild(document.createTextNode('[X] '));
      //toggler.namenode = user;
//toggler.setAttribute('namenode', user); //resultNodes[i];
toggler.id = user;
      //toggler.onmouseover = function(event) { event.target.style.cursor = 'pointer'; };
      //toggler.onmouseout = function(event) { event.target.style.cursor = 'default'; };
      toggler.addEventListener('mouseover', function(event) { event.target.style.cursor = 'pointer'; }, true);
      toggler.addEventListener('mouseout', function(event) { event.target.style.cursor = 'default'; }, true);
      toggler.style.fontSize = "7pt";
      //toggler.onclick = function(event) {
      toggler.addEventListener('click', function(event) {
//GM_log('in click event');
//GM_log(event.target);
         for(j = 0; j < document.cookie.split('; ').length; j++ ) {
            var oneCookie = document.cookie.split('; ')[j].split('=');
            if (oneCookie[0] == cookieName) {
               users = oneCookie[1].split(', ');
               break;
            }
         }
var user = event.target.id;
         //var user = encodeURI(event.target.namenode);
//var user = encodeURI(event.target.namenode.innerHTML);
//GM_log(user);
         notFound = true;
         for (var j = 0; j < users.length; j++) {
            if (users[j] == user) {
               users.splice(j, 1);
               notFound = false;
            }
         }
         if (notFound)
            users.push(user);
         if (users.length > 0) {
            var date = new Date();
            var days = 365;
            date.setTime(date.getTime() + (days*24*60*60*1000));
            var expires = '; expires=' + date.toGMTString();
            var value = users.join(', ');
            document.cookie = cookieName + '=' + value + expires + '; path=/';
         } else {
            document.cookie = cookieName + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
         }
         alert(decodeURI(user) + ' has been ' + (notFound ? 'added to' : 'removed from')
            + ' your hide list\n'
            + 'You must refresh the page to view the changes.');
      }, true);
      resultNodes[i].parentNode.insertBefore(toggler, resultNodes[i]);

      // If this user isn't in our hide list, skip to the next user
      if (notFound)
         continue;

      // Find the first element node in the containing row
      var elem = containingRow.firstChild;
      while (elem.nodeType != 1)
         elem = elem.nextSibling;

      // Create a span to control toggling
      var span = document.createElement('span');
      span.appendChild(document.createTextNode('Toggle Display'));
      span.setAttribute('class', 'smalltext');
      span.style.textDecoration = 'underline';
      span.style.fontWeight = 'bold';
      span.setAttribute('displaystate', 'none');
      toggler.addEventListener('mouseover', function(event) { event.target.style.cursor = 'pointer'; }, true);
      span.addEventListener('mouseover', function(event) { event.target.style.cursor = 'pointer'; }, true);
      span.addEventListener('mouseout', function(event) { event.target.style.cursor = 'default'; }, true);
      span.addEventListener('click',  function(event) {
         var displayState = event.target.getAttribute('displaystate');
         if (displayState == 'none')
            displayState = '';
         else
            displayState = 'none';
         event.target.setAttribute('displaystate', displayState);
         // Target user information
         elem = event.target.nextSibling;
         while (elem.nodeType != 1)
            elem = elem.nextSibling;
         if (elem.getAttribute && (elem.getAttribute('class') == 'smalltext'))
            elem.style.display = displayState;
         // Target post body
         elem = elem.parentNode.nextSibling;
         while (elem.nodeType != 1)
            elem = elem.nextSibling;
         if (elem.tagName.toUpperCase() == 'TD')
            elem.style.display = displayState;
         // Target post footer
         elem = elem.parentNode.nextSibling;
         while (elem.nodeType != 1)
            elem = elem.nextSibling;
         if (elem.tagName.toUpperCase() == 'TR')
            elem.style.display = displayState;
      }, true);

      // Insert the span after the username and before the <br>
      elem.insertBefore(span, elem.firstChild.nextSibling.nextSibling);
      // Insert a <br> after the username and before the span
      elem.insertBefore(document.createElement('br'), elem.firstChild.nextSibling.nextSibling);

      // Crawl down and remove the postdetails span
      elem = elem.firstChild;
      while (elem) {
         if (elem.getAttribute && elem.tagName.toUpperCase() == 'DIV'
            && elem.getAttribute('class') == 'smalltext')
            elem.style.display = 'none';
         elem = elem.nextSibling;
      }

      // Reset the elem pointer to the first table cell in the row
      elem = containingRow.firstChild;
      while (elem.nodeType != 1)
         elem = elem.nextSibling;

      // Move to the next table cell in the row
      elem = elem.nextSibling;
      while (elem.nodeType != 1)
         elem = elem.nextSibling;

      // Move inside that table cell and remove the postbody and postsig spans
      if (elem.tagName.toUpperCase() == 'TD')
         elem.style.display = 'none';
      elem = elem.parentNode.nextSibling;
      while (elem.nodeType != 1)
         elem = elem.nextSibling;
      if (elem.tagName.toUpperCase() == 'TR')
         elem.style.display = 'none';
   }
})();


Offline NYCMacUser

  • President
  • **************
  • Posts: 8297
  • Gender: Female
  • Bippidi Boppidi Boo!
Re: ignore user feature for Firefox
« Reply #1 on: December 31, 2007, 05:46:39 PM »
Will this work for Macs?

::crossing fingers and silently praying::
Women are like teabags.
We don't know our true strength
until we are in hot water! â€”Eleanor Roosevelt

Offline Harlan

  • Governor
  • ***********
  • Posts: 2102
  • Gender: Male
  • Lemon Pistachios
    • Photos...
Re: ignore user feature for Firefox
« Reply #2 on: December 31, 2007, 11:34:29 PM »
Will this work for Macs?

::crossing fingers and silently praying::

I have no idea. I think it should work on anything you can run Firefox and Greasemonkey on. Give it a shot and let us know...! :)


 

Visit our sister site Jackson Heights Life