Skip to content

Instantly share code, notes, and snippets.

@p3g4asus
Last active July 2, 2024 08:35
Show Gist options
  • 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.9
// @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:not([style])');
$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});
});
let $other = $(".AltriSanti:not(:has('a'))");
$other.each((idx, el) => {
let $e = $(el);
let $ec = $e.clone();
let $i, res;
maint = ($i = $ec.find('i')).text();
if (!maint)
maint = '';
else
maint = maint.trim();
$i.remove();
main = $ec.text().trim();
if ((res = /^-\s+(.+)/.exec(main))) {
main = res[1];
}
rv.push({nome: main, tipo: maint, l: ''});
});
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