Skip to content

Instantly share code, notes, and snippets.

@gerswin
Last active August 29, 2015 14:00
Show Gist options
  • Save gerswin/369683d1b87280d64e22 to your computer and use it in GitHub Desktop.
Save gerswin/369683d1b87280d64e22 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Laptop VIT
// @namespace http://use.i.E.your.homepage/
// @version 2.1
// @description enter something useful
// @match http://tienda.vit.gob.ve/inicio
// @require https://code.jquery.com/jquery-2.1.1.min.js
// @copyright 2012+, You
// ==/UserScript==
var beep = (function() {
var ctx = new(window.audioContext || window.webkitAudioContext);
return function(duration, type, finishedCallback) {
duration = +duration;
// Only 0-4 are valid types.
type = (type % 5) || 0;
if (typeof finishedCallback != "function") {
finishedCallback = function() {};
}
var osc = ctx.createOscillator();
osc.type = type;
osc.connect(ctx.destination);
osc.noteOn(0);
setTimeout(function() {
osc.noteOff(0);
finishedCallback();
}, duration);
};
})();
$(document).ready(function() {
var sites = ["paraguana-i", "paraguana-ii", "ipsfa","los-teques", "terrazas", "plaza-venezuela"];
check_funcion(sites);
});
function check_funcion(restantes) {
sitepost=restantes[0];
rest=restantes;
rest.shift();
console.log("Consultando "+sitepost);
$.post("http://tienda.vit.gob.ve/%27/ajaxform", {
formName: sitepost,
other: "attributes"
})
.done(function(data) {
hay = data.indexOf("No hay productos disponibles en esta tienda");
if (hay == -1) {
var resp=$(data).find('.listado_prods').html();
pagina="";
$.each($(resp).find('.prod'),function(index,value){
var link=$(value).find('a');
var url="http://tienda.vit.gob.ve"+link.attr("href");
var nombre=link.html();
$(value).find('.imgw,a,br').remove();
pagina+='<a target="_blank" href="'+url+'">'+nombre+'</a>';
pagina+='<br><b>Precio:</b>'+$(value).html();
pagina+="<hr>";
});
var newWindow = window.open("about:blank", "Comprar en "+sitepost);
newWindow.document.write(pagina);
if(!confirm("Hay productos disponibles en:"+sitepost+" , ¿Desea detener las consultas?")){
if(rest.length>0){
check_funcion(rest);
}
else{
setTimeout(function() {
location.reload();
}, 120000+(Math.floor((Math.random() * 180000)) ));
}
}
}else{
console.log("No hay productos en: "+sitepost + dameTime());
if(rest.length>0){
check_funcion(rest);
}
else{
var tiempoConsulta=120000+(Math.floor((Math.random() * 180000)));
console.log("Proxima consulta en: "+tiempoConsulta/1000+" segundos");
setTimeout(function() {
location.reload();
}, tiempoConsulta );
}
}
}).fail(function() {
console.log( "Error en el Post." );
location.reload();
});
}
function dameTime(){
var currentdate = new Date();
var datetime = ", ultimo chequeo: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ (currentdate.getHours()%12) + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
return datetime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment