Skip to content

Instantly share code, notes, and snippets.

@mala
Created March 10, 2010 11:49
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 mala/327794 to your computer and use it in GitHub Desktop.
Save mala/327794 to your computer and use it in GitHub Desktop.
presen to jpg extension
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
chrome.browserAction.onClicked.addListener(function(tab){
capture();
});
function capture(){
chrome.windows.getCurrent(function(w){
chrome.tabs.captureVisibleTab(w.id, function(d){
send_data(d);
chrome.tabs.getSelected(w.id, function(tab) {
/* your custom code here */
chrome.tabs.update(tab.id,
{ url: "javascript:Presen.next();void(0);" }
);
});
})
})
}
function send_data(data) {
var req = new XMLHttpRequest;
req.open("POST", "http://127.0.0.1:8080/recieve");
req.send(data);
}
</script>
</head>
<body>
</body>
</html>
{
"name": "capture screenshot",
"description": "capture screenshot",
"version": "0.0.1",
"background_page": "background.html",
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"browser_action": {
"default_title": "capture",
"default_icon": "capture.png"
}
}
#!/usr/local/bin/ruby
require 'webrick'
require 'fileutils'
require 'date'
require 'base64'
HTTP_OPTIONS = {
:Port => 8080,
:RequestTimeout => 60,
}
count = 0
recv_handler = Proc.new() {|req,res|
img = req.body
img.sub!('data:image/jpg;base64,', '')
open("./img/#{count}.jpg", "w") do |f|
f.binmode
f.print Base64.decode64(img)
f.close
end
count = count + 1
res.status = 200
res.body = 'SCREEN SHOT SERVER'
}
s = WEBrick::HTTPServer.new(HTTP_OPTIONS)
Signal.trap('INT') do
s.shutdown
end
s.mount_proc('/recieve', recv_handler)
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment