?

Log in

No account? Create an account
entries friends calendar profile It's Me Previous Previous Next Next
The Autobiography of Russell
Life from a different perspective
zimzat
zimzat
I'm really started to LiveJournal to be able to ignore all comments by a specific user.

Maybe there's some way to make a Greasemonkey script do that. Each comment is cased in a DIV called ljcmt###### and inside that div is an HTML link to a user's info that could be parsed to see who posted it.

Err, a little more work than I particularly want, especially in JavaScript.
13 comments or Leave a comment
Comments
swanhart From: swanhart Date: June 28th, 2005 07:23 pm (UTC) (Link)
unfortunately you can't include javascript in LJ styles, or it would be a lot easier.

Still, I think I could come up with a bookmarklet to do that. I've also wanted to automatically cut most meme entries, because they almost all are enclosed in <table> tags.

You would have to customize your style though to put the div around each comment.

Also, a firefox extension that allows you to automatically execute a bookmarklet when you visit a page from a certain domain would be cool...
zimzat From: zimzat Date: June 28th, 2005 07:30 pm (UTC) (Link)
That's pretty much what Greasemonkey does. I have a script already set up for livejournal to add ?/&style=mine to the url of journals so I can view them in my style.

LiveJournal's S2 styles already have the divs needed around each comment entry. Brad made a dynamic comment management script that makes use of them without modifying a single line of code. Dynamic hooks on links and all that jazz.
swanhart From: swanhart Date: June 28th, 2005 10:05 pm (UTC) (Link)
this should do the trick...
// ==UserScript==
// @name          Livejournal Comment Filter
// @namespace     http://www.hour13.com/swany
// @description   script to automatically filter comments by certain posters
// @include       http://www.livejournal.com/*
// ==/UserScript==

/* THIS IS AN ARRAY OF USERS TO HIDE COMMENTS FROM BY DEFAULT */
skipusers = { 'username1':true,
	      'username2':true, 
	    };

try {

	for (var d in LJ_cmtinfo) { 
		if (!isNaN(parseInt(d)) ) {
			user = LJ_cmtinfo[d]['u'];
			if (skipusers[user] == true) {
				var oDiv = document.createElement('div'); 
				var oA = document.createElement('a');     
				oA.setAttribute('onClick', 
       	                                 'document.getElementById("ljcmt' + d +                     
       	                                 '").style.display="block";this.style.display="none";');
				oA.innerHTML = "Unhide comment by " + user;
				oComment = document.getElementById('ljcmt' + d); // get the comment div
				oComment.style.display='none'; //hide it
				oComment.parentNode.appendChild(oDiv);  
				oDiv.appendChild(oA);	
	   		}
 		}
	}

}

catch (e) {}


swanhart From: swanhart Date: June 29th, 2005 06:17 pm (UTC) (Link)
hmm..

That should be
// @include http://*.livejournal.com/*
zimzat From: zimzat Date: June 29th, 2005 06:33 pm (UTC) (Link)
The real problem I noticed is that it only works on comments you have moderation control over (your own journal and communities you moderate). Thus, when viewing someone elses journal the comments aren't flagged in the array.

If the comments I'm looking to get rid of were on my journal I'd probably just delete or screen them. Be that as it is, I can't do that on other people's posts.

Thanks for the work, really. I have an idea how this is still possible but I'd have to do some research first. Most of my time is going into IK and a couple of other projects, though.
swanhart From: swanhart Date: June 29th, 2005 06:40 pm (UTC) (Link)
Ahh..

I'll have to fix it so it works on those pages by parseing the HTML.
I actually had that about halfway done when I saw the LJ_cmtinfo
array. I didn't realise that wasn't on all comment pages though.

I'll post it again when it works for all pages :)
zimzat From: zimzat Date: June 29th, 2005 06:55 pm (UTC) (Link)
In LiveJournal's Comment Manage JS the function setupAjax (near the bottom) goes through all the links on a page and adds a hook to them. I imagine you could do something similar with all the DIV tags. Just a thought, which is probably what you're already doing. >.>

PS: You should post the script somewhere. There are probably other people who would like something like this, although it will need a way to change the skip user list outside of the script (no clue).
swanhart From: swanhart Date: June 29th, 2005 07:05 pm (UTC) (Link)
Similar, but instead I'm grabbing all the DIV tags with the DOM and examining their ID values to see if they are comments.

I am writing a recursive function that will then parse all the child elements until they find one with a class attribute of ljuser, which is the lj username span, then I will parse the contents to pull the username. If the username is on the blacklist then the div will not be displayed.
zimzat From: zimzat Date: June 29th, 2005 08:27 pm (UTC) (Link)
Hmm... this could get complicated (or extremely erronious) unless there's a way to make sure the ljuser span occurs in the header. Any <lj user="example"> tags are automatically given the ljuser class.

The header is put in a div but doesn't have any easily identifiable tags.

Oh well. Some problems just have to be lived with I guess. :-)
swanhart From: swanhart Date: June 29th, 2005 08:35 pm (UTC) (Link)
well, I'm using XPATH to find the elements, and returning them in order, so the ljuser tag in the header should be the one I'm evaluating.
swanhart From: swanhart Date: June 29th, 2005 08:49 pm (UTC) (Link)

Try this...

It finds the comment divs, and iterates over them, finding a ljuser span in each, and selecting the A tag within that span that grabs the userinfo.

It then splits that on the "=" to get the username

// ==UserScript==
// @name          Livejournal Comment Filter
// @namespace     http://www.hour13.com/swany
// @description   script to automatically filter comments by certain posters
// @include       http://*.livejournal.com/*
// ==/UserScript==

/* THIS IS AN ARRAY OF USERS TO HIDE COMMENTS BY DEFAULT */
skipusers = { 'username1':true,
	    };

// first find the comment DIV elements
oComments = document.evaluate(
    "//div[starts-with(@id, 'ljcmt')]",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);


for (var i = 0; i < oComments.snapshotLength; i++) {
    thisDiv = oComments.snapshotItem(i);
    //find the first ljuser link in each of the divs
    oS = document.evaluate(
	"//div[@id='" + thisDiv.id + 
         "']//span[@class='ljuser']/a[starts-with(@href, 
         'http://www.livejournal.com/userinfo.bml?')]",
	document,
	null,
	XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
	null);	
    //extract the username portion from the ljuser link
    user = oS.snapshotItem(0).href.split('=')[1];
	
    if (skipusers[user]) {
	var oDiv = document.createElement('div'); 
	var oA = document.createElement('a');     
	oA.setAttribute('href', '#');   /*make it a "named anchor" so it  
                                          gets a link pointer
					  and return false in the onClick 
                                          to cancel navigation
                                         */
	oA.setAttribute('onClick', 
       	                'document.getElementById("' + thisDiv.id + 
                        '").style.display="block";
                         this.style.display="none";return false;');
	oA.innerHTML = "Unhide comment by " + user;
	thisDiv.parentNode.insertBefore(oDiv, thisDiv);

	/*this makes sure that the "comment is hidden" 
          text gets the same indentation as the original comment
        */
	oDiv.setAttribute('style', thisDiv.getAttribute('style'));

	//hide the original comment
	thisDiv.style.display = 'none';

	oDiv.appendChild(oA);	
    }

}
zimzat From: zimzat Date: June 29th, 2005 09:16 pm (UTC) (Link)

Re: Try this...

It's not liking something about the strings in that. =\

I 'fixed' the first one by removing the whitespace between lines (putting it all on one line) and another pops up. After doing the same thing to the second one it works. Thanks. :-)

Error: unterminated string literal
Source Code:
"']//span[@class='ljuser']/a[starts-with(@href,

Error: unterminated string literal
Source Code:
'").style.display="block";
swanhart From: swanhart Date: June 29th, 2005 09:36 pm (UTC) (Link)

Re: Try this...

No problem.

I made a few changes and posted it to my journal. It wasn't working for users that use styles with <table> tags instead of DIVs..

Doesn't really apply to you though, since you view everybodies journal with your style.
13 comments or Leave a comment