Skip to content

Instantly share code, notes, and snippets.

@adis-io
Created November 26, 2011 16:07
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 adis-io/1395911 to your computer and use it in GitHub Desktop.
Save adis-io/1395911 to your computer and use it in GitHub Desktop.
SYNC
function upload(image){
var xhr = new XMLHttpRequest();
xhr.open('GET', image.srcUrl, false);
xhr.responseType = 'arraybuffer';
xhr.send();
var mime = xhr.getResponseHeader('Content-type');
var blob = new WebKitBlobBuilder();
blob.append(xhr.response);
var file = blob.getBlob(mime);
var fd = new FormData();
fd.append("image[0]", file);
xhr.open('POST', 'http://image.torrent.kg/api/upload', false);
xhr.send(fd);
console.log(xhr.responseText);
var obj=JSON.parse(xhr.responseText)
if (obj.error==false)
{
chrome.tabs.create({url: "http://image.torrent.kg/info/"+obj.data[0].id})
}
else
{
chrome.tabs.create({url: "http://image.torrent.kg"})
}
}
chrome.contextMenus.create(
{
title: "Upload to image.torrent.kg",
contexts:["image"],
onclick: upload
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment