Greasemonkey phpBB ignore?

Talk about add-ons and extension development.
Post Reply
User avatar
Thumper's Evil Twin
Posts: 6422
Joined: December 9th, 2003, 3:52 pm
Location: Glasgow, Scotland
Contact:

Post by Thumper's Evil Twin »

Buming this because I've finally decided that killz0ring Jack is beneficial to my health.

That last script doesn't work if the user has a space in their name.

- Chris
User avatar
Spewey
Folder@Home
Posts: 5799
Joined: January 25th, 2003, 2:06 pm
Location: St. Paul, Minnes°ta

Post by Spewey »

Unarmed wrote:Names with odd characters can be escaped in CSS rules with the backslash:

Code: Select all

.phpbb_user_Unarmed\(inparans\)


Edit: can't do johann_p or Ol'Grumpy but got Jack. That has no spaces, comrade. Also woom's code is looking for * which is heavier and you don't need hide anyway. You unhide and close.

Code: Select all

  .phpbb_user_Jack :first-child > *,
  .phpbb_user_Jack :first-child +td { display: none; }

How do we do odd characters for dummies, Unarmed?
Unarmed
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post by Unarmed »

Here is wig_out_on_me's user script altered so that it can work with usernames with spaces in them. No other changes except for general formatting and some comments to help me read through it.

Code: Select all

// ==UserScript==
// @name          PHP User Hide
// @include       */viewtopic.php*
// @description   hides / unhides a user's posts - based on User Classes by Unarmed
// @exclude
// ==/UserScript==

(function() {
   // Get stored hidden users from cookie
   var users = [];
   var cookieName = "phpUserHide";
   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;
      }
   }

   // Find all the usernames in the page
   var results = document.evaluate("//span[@class='name']/b", 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) {
      var containingRow = resultNodes[i].parentNode.parentNode.parentNode;
      // Collapse whitespace
      var user = resultNodes[i].innerHTML.replace(/ /g, '');

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

      // Add relevant event handlers to user's name
      resultNodes[i].title = "double click to add or remove this user from your hide list";
      resultNodes[i].onmouseover = function(event) { event.target.style.cursor = 'pointer'; };
      resultNodes[i].onmouseout = function(event) { event.target.style.cursor = 'default'; };
      // On double-click, add or remove this user from the stored user list in the cookie
      resultNodes[i].ondblclick = function(event) {
         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;
            }
         }
         user = event.target.innerHTML.replace(/ /g, '');
         notFound = true;
         for (var j = 0; j < users.length; j++) {
            if (users[j] == user) {
               users.splice(j, 1);
               notFound = false;
            }
         }
         if (notFound)
            users.push(event.target.innerHTML.replace(/ /g, ''));
         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(event.target.innerHTML + ' has been ' + (notFound ? 'added to' : 'removed from')
            + ' your hide list\n'
            + 'You must refresh the page to view the changes.');
      };

      // 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', 'gensmallbold');
      span.style.textDecoration = 'underline';
      span.setAttribute('displaystate', 'none');
      span.onmouseover = function(event) { event.target.style.cursor = 'pointer'; };
      span.onmouseout = function(event) { event.target.style.cursor = 'default'; };
      span.onclick = function(event) {
         var displayState = event.target.getAttribute('displaystate');
         if (displayState == 'none')
            displayState = '';
         else
            displayState = 'none';
         event.target.setAttribute('displaystate', displayState);
         elem = event.target.nextSibling;
         while (elem) {
            if (elem.getAttribute && (elem.getAttribute('class') == 'postdetails'))
               elem.style.display = displayState;
            elem = elem.nextSibling;
         }
         elem = event.target.parentNode.nextSibling;
         while (elem.nodeType != 1)
            elem = elem.nextSibling;
         elem = elem.firstChild;
         while (elem) {
            if (elem.getAttribute && (elem.getAttribute('class') == 'postbody'
               || elem.getAttribute('class') == 'postsig'))
               elem.style.display = displayState;
            elem = elem.nextSibling;
         }
      };

      // 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.getAttribute('class') == 'postdetails'))
            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
      elem = elem.firstChild;
      while (elem) {
         if (elem.getAttribute && (elem.getAttribute('class') == 'postbody'
            || elem.getAttribute('class') == 'postsig'))
         elem.style.display = 'none';
         elem = elem.nextSibling;
      }
   }
})();


Spewey: Thumper is referring to this script, which does not require CSS selectors in userContent.css. For my older user script, however, you should be able to hide johann_p or Ol'Grumpy with <code>.phpbb_user_johann_p</code> and <code>.phpbb_user_Ol\'Grumpy</code>, but I haven't tried it myself.
User avatar
Spewey
Folder@Home
Posts: 5799
Joined: January 25th, 2003, 2:06 pm
Location: St. Paul, Minnes°ta

Post by Spewey »

Edit: ok, if I ever doubt you again, please remind me not to.

Unarmed has made a version that seems final enough to me. You can get it here.
Remember you need to install Greasemonkey* before you can right-click and "Install User Script..." on that link.
  • Double-clicking a username allows you to almost effortlessly killify or unkillify.
  • Tooltip and cursor change on hover over name to emphasize how it works.
  • Killified victims' name remains with a show/hide for individual posts.
  • It should work on other phpBBs as well.
  • The list goes in a cookie so you need those too.

Super special thanks to asqueella and wig_out_on_me! You guys all amaze me.

user testimonial wrote:I've been much a happier person since I started using the "Greasemonkey phpBB ignore?" script. One definite advantage is that I no longer find myself trying to gouge my eyes out after trying to comprehend the incomprehensible.

*You may want to try Greasemonkey 0.2.3 unofficial with trunk/nightly builds.
Last edited by Spewey on April 7th, 2005, 9:37 am, edited 4 times in total.
User avatar
Thumper's Evil Twin
Posts: 6422
Joined: December 9th, 2003, 3:52 pm
Location: Glasgow, Scotland
Contact:

Post by Thumper's Evil Twin »

Yeah, no css. Just Works. Rock.

- Chris
TychoQuad
Posts: 1263
Joined: December 11th, 2002, 12:30 am
Location: Australia

Post by TychoQuad »

Spewey, the link to greasemonkey 0.2.4 you provided didn't work! someone help, i downloaded the latest version, unaware that it was broken in the nightlies!
Unarmed
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post by Unarmed »

User avatar
Spewey
Folder@Home
Posts: 5799
Joined: January 25th, 2003, 2:06 pm
Location: St. Paul, Minnes°ta

Post by Spewey »

oops, The 0.2.4 was altered by asqueella and posted at EM GM page. Maybe he will see this and tell what the story is with the 0.2.6 he's got up there now instead as far as working on trunk builds.

Here's another 0.2.3 (I believe) that he mentions here which you can try in the meantime:


I talked to the GM author and he said 0.2.6 had bugs on the trunk builds but it seems to work for some people. Over my head....

And Unarmed's link is the official source for the script in case he makes any updates in the future.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

I did not touch 0.2.4.
User avatar
Spewey
Folder@Home
Posts: 5799
Joined: January 25th, 2003, 2:06 pm
Location: St. Paul, Minnes°ta

Post by Spewey »

Oh, sorry, I didn't mean to imply anything bad, that's just what I remembered the EM page had on it before. I'm just confused now.
Mook
Posts: 1752
Joined: November 7th, 2002, 9:35 pm

Post by Mook »

There is a copy of a pre-0.2.7 in the mailing list that's supposed to work. I personally have a hacked 0.2.6 that works too (see the same list for the changes I made).
poot.
rootyb
Posts: 52
Joined: April 11th, 2005, 8:46 pm

Post by rootyb »

Should this work on an SMF board?

You have no idea how much I'd love to use this, but I've tried double-clicking the name of the person I want to ignore, and it just sends me to their profile. (SMF 1.0 Beta 5 Public, if that matters)

If phpBB and SMF aren't *quite* similar enough, any chance of getting a port?
Unarmed
Posts: 4941
Joined: July 31st, 2003, 1:26 pm

Post by Unarmed »

It'd need to be adapted to work with SMF, since it produces different HTML.
rootyb
Posts: 52
Joined: April 11th, 2005, 8:46 pm

Post by rootyb »

Yeah, kinda figured as much.

Anyone fancy doin it? ;)

lol
Mook
Posts: 1752
Joined: November 7th, 2002, 9:35 pm

Post by Mook »

Yet another slightly modified version of Unarm's script. link

Changes:
- Differentiates between "John Doe" and "JohnDoe"
- Changed double-click on name to a [X] on the side, so I can double click on the name to select it and copy (useful for replies).

The changes are probably not significant enough to warrant keeping, I'm just posting this so I will be able to find it again after I wipe my profile :)
poot.
Post Reply