Greasemonkey / Javascript snippet for removing elements from a webpage
Friday, August 17th, 2007I use greasemonkey frequently and love the idea of modifiying the internet for your own purposes. It’s like open source web pages. I have several greasemonkey scripts on UserScripts.
A frequent use of greasemonkey is to remove elements from a web page, such as advertisments. This Javascript function takes an array of xpath queries and removes all those elements.
function remove_annoying( xpath_queries )
{
for( j=0; j
An example of this is:
var annoying_elements = new Array( "//*[@class='commerceTD']", "//*[@class='orange_bg_30']/..", "//*[@id='siBoxDiv']" );
remove_annoying( annoying_elements );
This function is used in my script to clean up tripadvisor, a site with travel listing.