Skip to content

Instantly share code, notes, and snippets.

@pandaman64
Last active August 29, 2015 14:01
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 pandaman64/3611a24d8b49cc6d3853 to your computer and use it in GitHub Desktop.
Save pandaman64/3611a24d8b49cc6d3853 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Into Wandbox
// @namespace https://twitter.com/__pandaman64__
// @include *
// ==/UserScript==
(function(){
function into_wandbox(str){
//Remove NBSPs
var new_str = str.replace(/\u00A0/gi, ' ');
//console.log(new_str);
//API home
var wandbox = "http://melpon.org/wandbox/api";
//Settings(these can be changed by users someday)
var language = "c++";
var compiler = "gcc-head";
var options = ["c++1y"];
//JSON post data
var post_data = {
"compiler": compiler,
"options": options.join(","),
"code": new_str
};
//post_data.created_at = new Date().toISOString(); //for permlink(but I cant get permlink)
//console.log(JSON.stringify(post_data));
//Post compile request.
GM_xmlhttpRequest({
method: "POST",
url: wandbox + "/compile.json",
//url: wandbox + "/permlink/",
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify(post_data),
onload: function(res){
console.log(res.responseText);
}
});
};
document.addEventListener(
"keydown",
function(e){
if(e.keyCode == 13){ //[Enter]
if(e.shiftKey && e.ctrlKey){
//Into Wandbox!
into_wandbox(window.getSelection().toString());
}
}
}
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment