Source for "Craigslist Spam Buttons v1.1"

By Ryan Stille
Has no other scripts.


// ==UserScript==
// @name            Craigslist Spam Buttons v1.1
// @namespace       http://www.stillnetstudios.com
// @description     Displays buttons on the item list so you can flag items as spam without having to click on the item and view it.
// Usually spam is pretty obvious and doesn't require viewing the item.
// I see a new "FREE 4gb Ipod Nano!!" item every day for example.
// @include         http://*.craigslist.*/*
// ==/UserScript==


var tables = document.getElementsByTagName("blockquote");
if (tables[1]) {
	var paras = tables[1].getElementsByTagName("p");
	var regex = new RegExp(/\w\w\w\/(\d+)\.html/);
	for (i=0;i< paras.length;i++) {
		anchors = paras[i].getElementsByTagName("a");
		if (anchors.length > 0) {
			href = anchors[0].getAttribute("href");
			if (retval = regex.exec(href)) {
				postingID = retval[1];
				newlink = document.createElement("a");
				newlink.setAttribute("href","http://flag.craigslist.org/?flagCode=15&postingID=" + postingID);
				newlink.setAttribute("style","font-size: 9px; padding-right: 6px;");
				newlink.setAttribute("title","Click to mark this item as spam.");
				newlink.setAttribute("onclick","return markAsSpam(" + postingID + ")");
				newlink.setAttribute("id","sl_" + postingID);
				newlink.innerHTML = '[spam]';
				paras[i].insertBefore(newlink,paras[i].firstChild);
				}
			}
		}
	}

// create a new image.  We'll mark items as spam by fetching the spam URL as the source
// for the image.  Tricky, huh?  This way it works in both Opera and FireFox.
tmpCLSBimg = new Image();
tmpFunction = function(postingID) {
	var newlink = document.createElement("a");
	newlink.setAttribute("style","font-size: 14px; padding-right: 11px; padding-left: 8px; color: red; font-weight: bold;");
	newlink.innerHTML = '&#x2713';
	tmpCLSBimg.src = "http://flag.craigslist.org/?flagCode=15&postingID=" + postingID;
	document.getElementById("sl_" + postingID).parentNode.replaceChild(newlink,document.getElementById("sl_" + postingID));
	// this only appears to work in Opera. If you know how to make it work in FF, let me know.
	document.status = "Marked item " + postingID + " as spam.";
	setTimeout('window.status = ""',2000);
	return false;
	}

// place the function into the window differently for Opera and FireFox
if (navigator.appName == "Opera") {
	window.markAsSpam = tmpFunction;
	}
else {
	unsafeWindow.markAsSpam = tmpFunction;
	}