// ==UserScript==
// @name AndhairaFilter
// @namespace http://www.rpgcodex.net/phpBB/AndhairaFilter
// @description Filters posts and threads started by specific users on RPGCodex
// @include http://www.rpgcodex.net/phpBB/*
// ==/UserScript==
// List of users whose posts are filtered.
var postfilter = new Array( 'Andhaira', 'UrielSeptimz', 'larpingdude14', 'Volourn' );
// true if specified element contains specified text, otherwise false.
function elementContainsText( el, str )
{
if( el.innerHTML.search( str ) != -1 )
return true;
return false;
}
// Determine current page:
// 1 - viewtopic.php
// 2 - viewforum.php
// 3 - posting.php
// 4 - search.php
// 0 - other
function getCurrentPageType()
{
var forumurl = 'www.rpgcodex.net/phpBB/';
if( location.href.search( forumurl + 'viewtopic.php' ) != -1 )
{
return 1;
}
else if( location.href.search( forumurl + 'viewforum.php' ) != -1 )
{
return 2;
}
else if( location.href.search( forumurl + 'posting.php' ) != -1 )
{
return 3;
}
else if( location.href.search( forumurl + 'search.php' ) != -1 )
{
return 4;
}
return 0;
}
function filterFromTopicView( usernames )
{
var spans = document.getElementsByTagName( 'span' );
var post_found = false;
for( var i = 0; i < spans.length; ++i )
{
// looking for offending posts
if( !post_found && spans[i].getAttribute('class') == 'name' )
{
for( var j = 0; j < postfilter.length; ++j )
{
if( elementContainsText( spans[i], postfilter[j] ) )
{
post_found = true;
break;
}
}
}
// found an offending post, looking for its body
if( post_found && spans[i].getAttribute('class') == 'postbody' )
{
//removing the post
spans[i].parentNode.parentNode.removeChild( spans[i].parentNode );
post_found = false;
}
}
}
function filterFromForumView( usernames )
{
var spans = document.getElementsByTagName( 'span' );
for( var i = 0; i < spans.length; ++i )
{
// looking for offending threads
if( spans[i].getAttribute('class') == 'name' )
{
for( var j = 0; j < postfilter.length; ++j )
{
if( !elementContainsText( spans[i], postfilter[j] ) )
continue;
// found an offending thread, gotta remove it
spans[i].parentNode.parentNode.parentNode.removeChild(
spans[i].parentNode.parentNode );
i = i == 0 ? 0 : i-1;
break;
}
}
}
}
function filterFromPostingView( usernames )
{
//this function works for now, but will need to be expanded
filterFromTopicView(usernames);
}
function filterFromSearchView( usernames )
{
//this function works for now, but will need to be expanded
var spans = document.getElementsByTagName('span');
//if there is postbody class span, then search results are posts
for( var i = 0; i < spans.length; ++i )
{
if( spans[i].getAttribute('class') == 'postbody' )
{
filterFromTopicView( usernames );
return;
}
}
filterFromForumView( usernames );
}
var page_type = getCurrentPageType();
switch( page_type )
{
case 1:
filterFromTopicView( postfilter );
break;
case 2:
filterFromForumView( postfilter );
break;
case 3:
filterFromPostingView( postfilter );
break;
case 4:
filterFromSearchView( postfilter );
break;
default:
break;
}