Created
November 7, 2012 12:36
-
-
Save adis-io/4031374 to your computer and use it in GitHub Desktop.
Расширение для Google Chrome. Позволяет из любой страницы загрузить картинку в другой хостинг картинок(image.torrent.kg) в 2 клика.
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
| 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); | |
| var xhr2 = new XMLHttpRequest(); | |
| xhr2.open('POST', 'http://image.torrent.kg/api/upload', true); | |
| xhr2.onload = function(e) { | |
| if (this.status == 200) { | |
| //console.log(xhr2.responseText) | |
| var obj=JSON.parse(xhr2.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"}) | |
| } | |
| } | |
| }; | |
| xhr2.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