// Copyright 2009 KARASZI Istvan <facebook@spam.raszi.hu>.
// All rights Reserved.
// ==UserScript==
// @name Facebook Status Cleaner
// @namespace http://userscripts.org/users/20715/scripts
// @description With this script you can clean the unwanted status messages on facebook.
// @include http://*.facebook.com/*
// ==/UserScript==
//
// <helper functions>
//
function _XPath( query, context ) {
if (arguments.length == 1) {
context = document;
}
var d = context;
if (context.ownerDocument) {
d = context.ownerDocument;
}
return d.evaluate(query, context, _nsResolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
function _nsResolver( prefix ) {
var ns = {
'xhtml': 'http://www.w3.org/1999/xhtml'
};
return ns[prefix] || null;
}
//
// </helper functions>
//
function _hideStory( story ) {
story.style.display = "none";
}
function _checkStoryItems() {
var home = _XPath("//div[@id='home_stream']");
if (home.snapshotLength != 1) {
return false;
}
var stories = _XPath("//div[contains(@class, 'UIStory')]", home.snapshotItem(0));
next_story:
for (var i = 0; i < stories.snapshotLength; i++) {
var story = stories.snapshotItem(i);
var text = story.textContent;
//
// check for content
if (text.match(/Take this/)) {
_hideStory(story);
continue next_story;
}
//
// check for anchors
var anchors = _XPath("/a[contains(@href, 'apps.facebook.com')]", story);
if (anchors.snapshotLength != 0) {
for(var j = 0; j < anchors.snapshotLength; j++) {
var a = anchors.snapshotItem(j);
var href = a.getAttribute("href");
if (href.match(/quiz/i)) {
_hideStory(story);
continue next_story;
}
}
}
}
}
_checkStoryItems();
// vim: ts=4 sw=4