Skip to content

Instantly share code, notes, and snippets.

@dims
Created September 15, 2008 14:15
Show Gist options
  • Save dims/10865 to your computer and use it in GitHub Desktop.
Save dims/10865 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "paste",
takes: {
status: noun_arb_text
},
modifiers: {},
preview: function(previewBlock, directObj) {},
execute: function(directObj) {
var statusText = directObj.text;
if (statusText.length < 1) {
displayMessage("Please enter some data to paste");
return;
}
file = encodeURIComponent("[gistfile1]");
quickPaste = "file_ext" + file + "=.js&file_name" + file + "=x&file_contents" + file + "=" + encodeURIComponent(statusText) + "&x=27&y=27";
updateUrl = "http://gist.github.com/gists";
req = new XMLHttpRequest();
req.open('POST', updateUrl, false);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(quickPaste);
if (req.status == 200) {
gitURL = req.responseText.match(/\git\@gist\.github\.com\:.*\.git/i);
newPasteURL = "http://gist.github.com/" + gitURL[0].match(/\d+/i);
Application.console.log("new paste at : " + newPasteURL);
displayMessage(newPasteURL);
} else {
displayMessage("Unable to paste error code : " + req.status + " status:" + req.statusText);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment