Skip to content

Instantly share code, notes, and snippets.

@p3g4asus
Last active June 5, 2023 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p3g4asus/047cab11f19ce6ebe4aa2d39152d0210 to your computer and use it in GitHub Desktop.
Save p3g4asus/047cab11f19ce6ebe4aa2d39152d0210 to your computer and use it in GitHub Desktop.
parsing santo del giorno
// ==UserScript==
// @name Saint of the day
// @namespace https://github.com/p3g4asus
// @version 2.3
// @description Format saint of the day
// @author p3g4asus
// @match https://www.santodelgiorno.it/*
// @icon https://www.santodelgiorno.it/image/sfondobodynew1.jpg?v
// @homepageURL https://gist.github.com/p3g4asus/047cab11f19ce6ebe4aa2d39152d0210
// @updateURL https://gist.github.com/p3g4asus/047cab11f19ce6ebe4aa2d39152d0210/raw/santodelgiorno.js
// @downloadURL https://gist.github.com/p3g4asus/047cab11f19ce6ebe4aa2d39152d0210/raw/santodelgiorno.js
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
let main = $('.NomeSantoDiOggi').text();
let maint = $('.TipologiaSantoDiOggi').text();
let $url = $('.SantoDiOggi').find('a');
let url = '';
let dt = /((?:[0-9]+|primo)\s+[a-zA-Z]+)\s+si venera/.exec($('span.Titolo:contains("si venera")').text());
let data = dt?dt[1]:'data N/A';
$url.each((_, el) => {
let $e = $(el);
if ($e.text().indexOf('> Continua') >= 0) {
url = $e.prop('href');
return false;
}
})
let rv = [{nome: main, tipo: maint, l: url}];
let $startLst = $('.ElencoSanto');
let $links = $startLst.find('a.NomeSantoEl');
$links.each((idx, el) => {
let $e = $(el);
main = $e.text();
url = $e.prop('href');
let $d = $e.closest('div').next('div');
let $i;
maint = '';
if ($d.length && !$d[0].attributes.length && $d.children().length == 1 && ($i = $d.children('i')).length == 1)
maint = $i.text();
rv.push({nome: main, tipo: maint, l: url});
});
rv.forEach((v) => {
if (v.l.length) {
$.get(v.l, (html) => {
let $page = $(html);
let grabber = (...args) => {
let sel = '', field;
args.forEach((arg, idx) => {
if (idx == args.length - 1)
field = arg;
else
sel += 'span:contains("' + arg +'")' + (idx == args.length - 2?'':',');
});
let $s = $page.find(sel).next().next('span');
if ($s.length) {
let patrs = [];
$s.children('a').each((_, el) => {
let $e = $(el);
patrs.push($e.text());
});
if (patrs.length) {
v[field] = patrs;
}
}
};
grabber('Patrono di', 'Patrona di', 'Patroni di', 'Patrone di', 'patr');
grabber('Protettore', 'Protettrice', 'Protettori', 'Protettrici' , 'prot');
}).always(() => {
v.done = true;
});
}
else
v.done = true;
});
let intv = setInterval(() => {
let done = true;
rv.forEach((v) => {
if (!v.done) {
done = false;
return false;
}
});
if (done) {
clearInterval(intv);
let outstr = '';
rv.forEach((v, idx) => {
if (v.nome.length)
outstr += v.nome + ' - ' + (v.tipo.length?v.tipo:'N/A') + (v.patr? ' {Patr: ' +v.patr.join(', ') + '}':'') + (v.prot? ' [Prot: ' +v.prot.join(', ') + ']':'') + (idx == rv.length - 1?'': ' | ');
});
if (outstr.length) {
console.log(JSON.stringify(rv, null, 2));
GM_setClipboard('*' + data + '* ' + outstr);
console.log(outstr);
}
}
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment