Last active
August 29, 2015 14:01
-
-
Save pandaman64/3611a24d8b49cc6d3853 to your computer and use it in GitHub Desktop.
This file contains 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
// ==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