Nice Idea
|
|
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);
}
|
|
|
Hey would you mind if I added this code to my comment fixer script? |
|
|
sure, add away! |
|
|
I changed my code a bit, and added your suggestion (thanks). |
|
|
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);
|
|
|
true, added a check for that. (although... what if you had a moral dilemma with yourself? :P) |
|
|
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.
|
|
|
Avindra Gool... wrote:ROFLMAO! sizzlemctwizzle wrote: Avindra Gool... wrote:Refreshing to see collaboration of script wrights here. :) |
|
|
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! :) |
|
|
JoeSimmons wrote: |
|
|
fixed (thanks to marti for the quick tip) |
|
|
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>, ...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. ;) :) |