Skip to content

Instantly share code, notes, and snippets.

@nikgalushko
Created November 14, 2014 21:03
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 nikgalushko/080df65cdade35c3848d to your computer and use it in GitHub Desktop.
Save nikgalushko/080df65cdade35c3848d to your computer and use it in GitHub Desktop.
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