Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created April 26, 2011 02:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbqx/941714 to your computer and use it in GitHub Desktop.
Save nbqx/941714 to your computer and use it in GitHub Desktop.
# -*- 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