Created
November 14, 2014 21:03
-
-
Save nikgalushko/080df65cdade35c3848d to your computer and use it in GitHub Desktop.
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
chrome.browserAction.onClicked.addListener( | |
function(tab) { | |
var currentURL = tab.url; | |
if (currentURL.indexOf("gyazo") == -1) | |
return; | |
console.log(currentURL.split("/")); | |
var src = "http://i.gyazo.com/" + currentURL.split("/").pop() + ".png"; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", "http://qps.ru/api?url=" + src + "&format=text", true); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == 4) { | |
console.log(xhr.responseText); | |
executeCopy(xhr.responseText); | |
} | |
} | |
xhr.send(); | |
} | |
); | |
function executeCopy(text) { | |
var input = document.createElement('textarea'); | |
document.body.appendChild(input); | |
input.value = text; | |
input.focus(); | |
input.select(); | |
document.execCommand('Copy'); | |
input.remove(); | |
} | |
//gyazo short img link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment