Created
November 26, 2011 16:05
-
-
Save adis-io/1395907 to your computer and use it in GitHub Desktop.
ASYNC
This file contains 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
function upload(image){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', image.srcUrl, true); | |
xhr.responseType = 'arraybuffer'; | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
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', true); | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
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"}) | |
} | |
} | |
}; | |
xhr.send(fd); | |
... | |
} | |
}; | |
xhr.send(); | |
} | |
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