Created
May 15, 2011 09:06
-
-
Save NeoCat/972987 to your computer and use it in GitHub Desktop.
Send 'Chrome to Phone' request usig CGI and bookmarklet
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
javascript:window.open('http://localhost/utils/chrome2phone.cgi?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href),%20'_blank',%20'width=200,height=100');undefined; |
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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'mechanize' | |
require 'cgi' | |
mail = '[email protected]' | |
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