Skip to content

Instantly share code, notes, and snippets.

@NeoCat
Created May 15, 2011 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeoCat/972987 to your computer and use it in GitHub Desktop.
Save NeoCat/972987 to your computer and use it in GitHub Desktop.
Send 'Chrome to Phone' request usig CGI and bookmarklet
javascript:window.open('http://localhost/utils/chrome2phone.cgi?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href),%20'_blank',%20'width=200,height=100');undefined;
#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
require 'cgi'
mail = '__________@gmail.com'
password = '____________'
agent = Mechanize.new
cookie_jar = "c2p.cookie" # ログイン失敗した場合はこのファイルを削除してやり直し
cgi = CGI.new
print "Content-type: text/plain\n\n"
if File.exist?(cookie_jar)
agent.cookie_jar.load(cookie_jar)
else
puts "Logging in ..."
agent.get('https://chrometophone.appspot.com/signin?extret=chrome-extension://a/help.html&ver=5')
agent.page.form_with(:action => /ServiceLoginAuth/){|form|
form.field_with(:name => 'Email').value = mail
form.field_with(:name => 'Passwd').value = password
form.click_button
}
#puts agent.page.uri
script = agent.page.at('body>script').to_s
script.match(/location\.replace\(\"(.*?)\"\)/)
addr = eval("\"#$1\"")
agent.get(addr)
agent.cookie_jar.save_as(cookie_jar)
#File.chmod(0600, cookie_jar)
end
agent.post('https://chrometophone.appspot.com/send?ver=5', {"url" => cgi['url']}, {"X-Same-Domain" => "true"})
puts agent.page.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment