What am I looking at here?
Ben Giddings
bg-ruby at infofiend.com
Tue Sep 6 18:39:52 EDT 2005
Ok, I managed a nice little mousehole script, but doing it brought up all
kinds of questions.
Here's the script:
MouseHole.script do
# declaration
name "Google Ad Scrubber"
namespace "bg-ruby at infofiend.com"
description "Removes ads from Google search results"
# Match google search results
include_match %r{^http://(www\.)?google.com/search}
version "0.1"
rewrite do |request, response|
right_sponsored_links = document.elements['//table[@width="25%" and
@align="right"]']
if right_sponsored_links
right_sponsored_links.parent.delete(right_sponsored_links)
end
loop do
top_sponsored_links = document.elements['//div[@class="ch"]']
break if top_sponsored_links.nil?
top_sponsored_links.parent.delete(top_sponsored_links)
end
end
end
And here are the questions:
* Does it have to be named foo.user.rb to be recognized when I put it in
the userScripts directory?
* What if I want it to match every URL, is there a good way to do that?
* What is "document"? The wiki docs say it's an HTree, but when I click on
that link I see nothing named "elements". Primitive debugging seems to
suggest it's a REXML::Document...?
* XPath seems to say that '//div[@class="ch"]' should give me all the div
nodes with a class "ch", but document.elements[XPATH] seems to only give
me one, so I have to loop
If you can help me understand this stuff, I'll try to update the wiki dox.
Ben
P.S. Right now the proxy job in my web browser is being handled by Privoxy,
but I think with a little work I can get Mousehole to do all that and
more...
More information about the Mousehole-scripters
mailing list