Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created December 8, 2011 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/1446948 to your computer and use it in GitHub Desktop.
Save rlemon/1446948 to your computer and use it in GitHub Desktop.
nitstorm
function codeRunner(){
var cb = document.getElementById("checkbox"), ppab = document.getElementById("ppa-box"); // checkbox is used twice, no need to select it twice. Same for ppa-box (referenced three times, called twice)
// Unlock PPA when Checkbox is ticked
cb.onclick = function(){
if(cb.checked){
ppab.disabled=false;
}
else
{
ppab.disabled=true;
ppab.value="";
}
}
//Form submission
document.getElementById("main-form").onsubmit = function(){
// Get Value from Form
var packageValue = document.getElementById("package-box").value;
var ppaValue = ppab.value;
// Code Mangling to achieve Markdown
var imageCode = "<b> [" + packageValue + " ![software_center_icon](http://i.imgur.com/puwkM.png)](http://apt.ubuntu.com/p/" + packageValue + ") </b><br /><br />";
var mandatoryLine = "<i>Run the following to install the package via a terminal (Default keyboard shortcut: <kbd>Ctrl</kbd><kbd>Alt</kbd><kbd>T</kbd>) </i><br />";
var packageInstruc = "sudo apt-get update && sudo apt-get install " + packageValue;
var ppaInstruc = "sudo add-apt-repository " + ppaValue
// Final Usage Variables
var packageOnly = imageCode + mandatoryLine + "<pre>" + packageInstruc + "</pre>";
var ppaPackage = mandatoryLine + "<pre>" + ppaInstruc + "<br />" + packageInstruc + "</pre>";
// Code output into text area
var code = document.getElementById("code"); // this doesn't really need to be done, but save yourself a few bytes.
if(ppaValue == ""){
code.appendChild(document.createTextNode(packageOnly));
}
else{
code.appendChild(document.createTextNode(ppaPackage));
}
return false;
}
}
window.onload = function(){
codeRunner();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment