Skip to content

Instantly share code, notes, and snippets.

@esteban22x
Created October 15, 2015 04:30
Show Gist options
  • Save esteban22x/825feabf00131a1831d3 to your computer and use it in GitHub Desktop.
Save esteban22x/825feabf00131a1831d3 to your computer and use it in GitHub Desktop.
Calculadora básica para saber cuanta nota se necesita para pasar la materia
// ==UserScript==
// @name Cuanto Me Falta
// @namespace http://esteban22x.com
// @version 0.1
// @description Calculadora de Cuanto Me Falta
// @author Duvan Esteban Delgado
// @match http://190.5.199.25:8083/notas/wForms/wfConsultNotas.aspx
// @require http://code.jquery.com/jquery-1.11.3.min.js
// @grant GM_addStyle
// ==/UserScript==
$(document).ready(function(){
var elementos = '<br><fieldset><legend>Cuanto Me falta:</legend>'
+'<label for="selector">Rellenar con </label>'
+'<select>'
+'<option value="1">Nada</option>'
+'</select><p></p><label for="n1">Nota 1: </label><input type="text" value="0"><label for="n2">Nota 2: </label> <input type="text" value="0">'
+'<p></p><button>Calcular</button><p></p><span></span></fieldset>';
$("table").after(elementos);
GM_addStyle("fieldset input[type='text']{width: 30px} fieldset > label,button,span{margin-left:30px}fieldset select{width: 50%}fieldset{font-family: Arial,serif;font-size:14px;width: 320px;margin: 0 auto}");
contador = 2;
$("table tr td:first-child").each(function(){
$("select").append("<option value='"+contador+"'>"+$(this).html()+"</option>");
contador++;
});
$("select").change(function(){
seleccionado = $("select option:selected").val();
if (seleccionado!=="1"){
valor = "tr:nth-child("+seleccionado+") td:nth-child(3)";
$("fieldset input[type='text']")[0].value = $(""+valor).html().replace(",",".");
valor2 = "tr:nth-child("+seleccionado+") td:nth-child(4)";
$("fieldset input[type='text']")[1].value = $(""+valor2).html().replace(",",".");
}else{
$("fieldset input[type='text']")[0].value = ""+0;
$("fieldset input[type='text']")[1].value = ""+0;
}
});
$("button").on('click',function(w){
pasar();
return false;
});
unsafeWindow.pasar = function(){
console.log("pasa");
var n1= $("fieldset input[type='text']")[0].value;
var n2= $("fieldset input[type='text']")[1].value;
mostrar = ( typeof calcula(n1,n2)==="number") ? "Necesitas minimo un "+calcula(n1,n2) : ""+calcula(n1,n2);
$("fieldset span").html(mostrar);
};
function calcula(n1,n2){
//Calculo cuanto falta y hago el redondeo centesimal
if (n1>=0 && n1<=5 && n2>=0 && n2<=5){
devuelvo = ((n1*0.3 + n2*0.35)-3)/ -0.35;
devuelvo=Math.round(devuelvo*100)/100;
if (devuelvo>5){
devuelvo = "No pasas";
}else if(devuelvo < 0){
devuelvo = "Ya la tienes ganada :)";
}
}else{
devuelvo = "Formato Invalido";
}
return devuelvo;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment