Created
April 26, 2011 02:55
-
-
Save nbqx/941714 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#earthquake.gem plugin | |
#javascript via phantomjs | |
require 'tempfile' | |
def do_bmklt(js,url) | |
tmp = Tempfile.new("tmpjs") | |
begin | |
tmp.puts js | |
tmp.close | |
`/usr/bin/env phantomjs #{tmp.open.path} #{url}` | |
ensure | |
tmp.close true | |
end | |
puts "done for #{url}" | |
end | |
Earthquake.init do | |
command :js do |m| | |
scrt = File.open(__FILE__).read.gsub(/.*__END__/m,"") ##cannot use DATA.read | |
tweet = twitter.status(m[1])["text"] | |
tweet.scan(/http[s]?\:\/\/[\w\+\$\;\?\.\%\,\!\#\~\*\/\:\@\&\\\=\_\-]+/) do |u| | |
if confirm "do bookmarklet? '#{u}'" | |
async do | |
do_bmklt(scrt,u) | |
end | |
end | |
end | |
end | |
end | |
__END__ | |
if (phantom.state.length === 0) { | |
var address = phantom.args[0]; | |
phantom.state = 'ss'; | |
phantom.viewportSize = { width: 480, height: 600 }; | |
phantom.open(address); | |
} else { | |
phantom.render('screenshot.png'); | |
phantom.exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment