Skip to content

Instantly share code, notes, and snippets.

@s-nt-s
Last active April 10, 2023 20:42
Show Gist options
  • Save s-nt-s/b7451a661e20c4baa2e0eef5724cecdc to your computer and use it in GitHub Desktop.
Save s-nt-s/b7451a661e20c4baa2e0eef5724cecdc to your computer and use it in GitHub Desktop.
Avsisa cuando hay una cita disponible en el INSS de Madrid
// ==UserScript==
// @name Cita INSS
// @version 1
// @include https://sp.seg-social.es/*
// @run-at document-end
// @grant none
// ==/UserScript==
/* INSTRUCCIONES
1. Instalra extensiones Tampermonkey o Greasemonkey según se use chrome/chromium o firefox:
* https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=es
* https://addons.mozilla.org/es/firefox/addon/greasemonkey/
2. Agregar script a la extensión
En Greasemonkey es:
1. pulsando en Nuevo script de usuario...
2. pegando el contenido de cita-inss.js en la ventana emergente
3. pulsando guardar
*/
function mySetTimeout(cb, ms) {
const begin = performance.now();
const channel = mySetTimeout.channel ??= new MessageChannel();
const controller = new AbortController();
channel.port1.addEventListener("message", (evt) => {
if(performance.now() - begin >= ms) {
controller.abort();
cb();
}
else if (evt.data === begin) channel.port2.postMessage(begin);
}, {
signal: controller.signal
});
channel.port1.start();
channel.port2.postMessage(begin);
}
function mySleep(s) {
return new Promise(resolve => mySetTimeout(resolve, s*1000));
}
function myBeep(duration, frequency, volume, type, callback) {
// https://stackoverflow.com/a/29641185
const audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);
const oscillator = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
if (volume){gainNode.gain.value = volume;}
if (frequency){oscillator.frequency.value = frequency;}
if (type){oscillator.type = type;}
if (callback){oscillator.onended = callback;}
oscillator.start(audioCtx.currentTime);
oscillator.stop(audioCtx.currentTime + ((duration || 500) / 1000));
}
async function my_hack_ajax() {
if (window["jQuery"]==null) return false;
if (jQuery("div.pr_spinner:visible").length) {
console.log("spinnner");
return false;
}
const gtxt = function(node, txt) {
return jQuery(node).filter((i, n)=>n.textContent.trim()==txt);
}
const ok = gtxt("p.pr_pMensaje", "Se le proporcionará la primera cita disponible para la fecha y hora que seleccione en cualquier oficina de la provincia indicada anteriormente.");
if (ok.filter(":visible").length) {
window.fuckyeah = true;
myBeep();
return true;
}
if (window.fuckyeah) return;
//if (gtext("*", "La aplicación está trabajando, por favor, espere").length) return;
const click = function() {
const n = gtxt.apply(this, arguments);
if (n.length==0) return false;
console.log("CLICK - "+arguments[1]);
n.click();
return true;
}
const tc = jQuery("#tipoCita");
if (tc.length) {
tc.val("2").change();
jQuery("#provincia").val("28").change();
jQuery("#SIGUIENTE").click();
}
click("span", "ATENCIÓN TELEFÓNICA MEDIANTE CITA");
return true;
}
function to_script(code) {
const script = document.createElement("script");
script.textContent = code.toString();
return script;
}
setInterval(function(){
if (document.head == null) return;
if (!document.head._done) {
document.head.appendChild(to_script(mySetTimeout));
document.head.appendChild(to_script(mySleep));
document.head.appendChild(to_script(myBeep));
document.head.appendChild(to_script(my_hack_ajax));
document.head._done=true;
}
if (document.body) {
document.body.appendChild(to_script(`
${my_hack_ajax.name}()
`));
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment