Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Unipa Subscription Checker
// @version 1.0
// @description Check Subscription
// @author Francesco Cannizzaro
// @match https://immaweb.unipa.it/immaweb/private/docenti/esami/iscrizioneLezioni.seam*
// @require https://code.jquery.com/jquery-3.2.0.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
var table = $("table[id*='iscrizioniEffettuateTable'] tbody").first();
var array = $("tr:has(tr input[value=Visualizza])", table);
var title = $("h1.heading-title");
var makeForm = (list) => {
var form = {};
for (var i = 0; i < list.length; i++) {
var ele = $(`input[name*=${list[i]}]`).first();
form[ele.attr('name')] = ele.val();
}
return form;
};
var request = (tr, cb) => {
var visualizza = $('input[value=Visualizza]', tr);
if (visualizza.length > 0) {
var form = makeForm(['ViewState', 'docenteRichiestoId', 'insegnamentoRichiestoIdText', 'creditiRichiestiIdText', 'codiceInsegnamentoIdText']);
form[visualizza.attr('name')] = visualizza.val();
for (var key in form) {
if (key.indexOf(':') > 0) {
var split = key.split(':')[0];
form[split] = split;
break;
}
}
GM_xmlhttpRequest({
method: "POST",
url: "https://immaweb.unipa.it/immaweb/private/docenti/esami/iscrizioneLezioni.seam",
data: $.param(form),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
onload: (response) => {
cb();
domParse(response.responseText, tr, visualizza);
}
});
return;
}
cb();
};
var domParse = (body, tr, visualizza) => {
var html = jQuery.parseHTML(body);
var t = $("table[id*='materialeDidatticoList'] tbody", html);
var titles = [];
$("tr", t).each(function() {
var key = $('td', this).first().text().trim();
if (!localStorage.getItem(key)) {
titles.push($("td:eq(1)", this).text());
}
});
console.log(titles);
if (titles.length > 0) {
tr.remove();
titles.forEach(title => {
var p = $('<tr><td colspan=8><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAA5klEQVR4AaXUP0rGQBBA8VEQN4WCnXoOMd8FbERPZCEWdpJ8YG2h+A9S2GihrYVRksJLiOgBJGvgWYRAJiGZBN/UP1iWnZV/x4wNhGo2CRE9gp41vvFcEzLjBs8nq8PglHZRPwjYp6TdL7u4Ljgmw9NXQcqhBu9YZRo8ohME3b0G5yY4a4KA3ASvuBoscgcmgISFCsxhFIC4AvFoENVHShjTbX0kwfGG1QvLzWu9mHatwpMJHqY+jVyDI1IK+vrhmYPu83bsUdLOs8PSlAU6sVb0C88VIdtcUvDByjDQn8A6W4gBrPkDds8+0SQjqm4AAAAASUVORK5CYII="><span>' + title + '</span></td></tr>');
$("img, span", p)
.css('vertical-align', 'middle')
.css('margin-right', '16px');
$('td', p)
.css('background', '#315572')
.css('font-weight', 'bold')
.css('cursor', 'pointer')
.css('border-color', '#507a9b')
.css('color', '#fff');
p.click(() => {
visualizza.click();
});
table.prepend(p);
});
table.prepend(tr);
}
};
var original = title.text();
var next = (i) => {
if (i < array.length) {
title.html(original + ' <small>' + $("td:eq(1)", array[i]).text() + '...</small>');
request($(array[i]), () => {
next(i + 1);
});
} else {
title.html(original);
}
};
next(0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.