UserScripts > Report Spammer

By Avindra V.G. Last update Aug 28, 2009 — Installed 194 times.

Nice Idea

in
Subscribe to Nice Idea 12 posts, 3 voices



sizzlemctwizzle Scriptwright

This is a cool idea. I made the button a link to make it work with my us.o comment fixer script. I also put in a confirm dialog.

// ==UserScript==
// @name           UserScripts > Report Spammer
// @namespace      #aVg
// @include        http://userscripts.org/topics/*
// @version        0.1
// @description    Down with spam!
// ==/UserScript==
var vcards=document.evaluate("//td[@class='author vcard']",document,null,6,null), vcard, i=vcards.snapshotLength;
while(vcard=vcards.snapshotItem(--i)) {
	var r=document.createElement("a");
	r.href="#";
	r.className = "utility";
	r.textContent="Report Spam";
	r.addEventListener("click", function(e) {
		this.disabled=true;
		var l=this.parentNode.childNodes[5].lastChild;
		var post=this.parentNode.childNodes[1].childNodes[1];
		
		var btn=this;
		var ref="http://"+location.host+"/topics/9/posts";
		var spammer=document.evaluate("./a[@href='"+l.pathname+"']",document.getElementById("right"),null,9,null).singleNodeValue.title;
		if (confirm('Report '+spammer+' as a spammer?')) {
		  var report="<a href=\""+l.pathname+"\">"+spammer+"</a> is a <a href=\""+l.pathname+"/posts\">spammer</a>, most recently on topic <a href=\""+location.pathname+location.search+"\">"+
			document.getElementById("topic-title").firstChild.nodeValue.replace(/\s+/g," ").replace(/^\s+|\s+$/,"").replace(/"/g,""") +
			"</a>, with <a href=\""+post.pathname+post.search+post.hash+"\">this post</a>.";
		  GM_xmlhttpRequest({
			  url : ref,
			  method : "POST",
			  data : "authenticity_token="+encodeURIComponent(unsafeWindow.auth_token)+"&post%5Bbody%5D="+encodeURIComponent(report)+"&commit=Post+reply",
			  headers : {
				"Content-Type" : "application/x-www-form-urlencoded",
				"Referer" : ref
			  },
			  onload : function() {
				btn.textContent="Reported!";
			  }
		  });
                }
        e.preventDefault();
	},false);
        vcard.appendChild(document.createElement("br"));
	vcard.appendChild(r);
}

 
sizzlemctwizzle Scriptwright

Hey would you mind if I added this code to my comment fixer script?

 
Avindra V.G. Script's Author

sure, add away!

 
Avindra V.G. Script's Author

I changed my code a bit, and added your suggestion (thanks).

 
sizzlemctwizzle Scriptwright

You might also not want to show the report link on your own posts.

if (!document.evaluate(".//span[@class='edit']",vcard,null,9,null).singleNodeValue) vcard.appendChild(r);

 
Avindra V.G. Script's Author

true, added a check for that. (although... what if you had a moral dilemma with yourself? :P)

 
sizzlemctwizzle Scriptwright

I wasn't aware evaluate could return a boolean value so thanks for that. I totally forgot I could use continue. One of my bad programming habits that I'm trying to break is that I wrap things in if-statements too often.
if you'd like an eye patch for your kitty check out http://eyepatchforkitty.com ... crap! you were right and now I can't report myself!!!

 
Marti Scriptwright

Avindra Gool... wrote:
... (although... what if you had a moral dilemma with yourself? :P)
ROFLMAO!

sizzlemctwizzle wrote:
Hey would you mind if I added this code to my comment fixer script?
Avindra Gool... wrote:
sure, add away!
Refreshing to see collaboration of script wrights here. :)

 
Marti Scriptwright

Script problem with the new site layout.

Just wanted to let you know that the new site layout breaks your script. Thanks again for this killer idea and allowing it to be shared! :)

 
sizzlemctwizzle Scriptwright

JoeSimmons wrote:
I get this when I click "Report Spam."

Error: document.evaluate("./a[@href='" + l.pathname + "']", document.getElementById("right"), null, 9, null).singleNodeValue is null

 
Avindra V.G. Script's Author

fixed (thanks to marti for the quick tip)

 
Marti Scriptwright

Just a note... this script has been partially (2/3rds) broken for a while... I've tried to keep the var names as close to the same style as possible but here's the fix that I'm using currently:

var trunc = l.text.match(/(.*)\.\.\.$/i);
if (trunc) {
  var spammerTemp = document.evaluate(
    "./a[starts-with(@title, '" + trunc[1] + "' )]",
    $("right"),
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
  ).singleNodeValue;

  if (spammerTemp.title != trunc[0])
    alert('WARNING: Name truncation detected! \n\nDouble check report for accuracy.');

} else {
  var spammerTemp = document.evaluate(
    "./a[@title='" + l.text + "']",
    $("right"),
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
  ).singleNodeValue;
}

var spammerLink = spammerTemp.pathname;
var spammer = spammerTemp.title;
...
var report = "<a href=\"" + spammerLink + "\">" + spammer + "</a> is a <a href=\"" + spammerLink + "/posts\">spammer</a>, ...

Looks like it misses out on your nick too because it's so long... messaged Jesse about it... but at least this temp fix works "most of the time" :)
Had a few moments to add a name truncation test to it until Senior Jesse gets around to fixing the attribute. Now catches all of 'em. ;) :)

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel