Aggiungi nuove funzionalità e miglioramenti al GAIA Swissknife
This commit is contained in:
parent
5c03e3af71
commit
749080549e
1 changed files with 543 additions and 347 deletions
|
|
@ -7,31 +7,152 @@
|
||||||
// @version 0.4.4-beta
|
// @version 0.4.4-beta
|
||||||
// @description Aggiunge funzionalità alle pagine di GAIA
|
// @description Aggiunge funzionalità alle pagine di GAIA
|
||||||
// @match https://gaia.cri.it/*
|
// @match https://gaia.cri.it/*
|
||||||
// @grant none
|
// @require https://code.jquery.com/jquery-3.6.0.min.js
|
||||||
|
// @require https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js
|
||||||
|
// @resource DataTablesCSS https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css
|
||||||
|
// @grant GM_addStyle
|
||||||
|
// @grant GM_getResourceText
|
||||||
// @run-at document-idle
|
// @run-at document-idle
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
GM_addStyle(GM_getResourceText("DataTablesCSS"));
|
||||||
|
|
||||||
|
(function($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
console.log("GAIA Swissknife: Inizializzazione in corso!");
|
||||||
|
|
||||||
// Recupera la versione dallo script se disponibile, altrimenti usa un valore di fallback
|
// Recupera la versione dallo script se disponibile, altrimenti usa un valore di fallback
|
||||||
const currentVersion = (typeof GM_info !== 'undefined' && GM_info.script && GM_info.script.version) ? GM_info.script.version : 'x.x';
|
const currentVersion = (typeof GM_info !== 'undefined' && GM_info.script && GM_info.script.version) ? GM_info.script.version : 'x.x';
|
||||||
|
|
||||||
// Controlla se jQuery è caricato, altrimenti lo carica
|
function applyStyleFixes() {
|
||||||
function ensureJQuery(callback) {
|
const url = window.location.href;
|
||||||
if (window.jQuery) {
|
|
||||||
callback(window.jQuery);
|
if (url.match(/\/profilo\/\d+\/curriculum\//)) {
|
||||||
|
console.log("GAIA Swissknife: Ricostruzione celle curriculum (versione pulita)...");
|
||||||
|
|
||||||
|
$("td.piu-piccolo").each(function (cellIndex) {
|
||||||
|
const $td = $(this);
|
||||||
|
const rawNodes = Array.from(this.childNodes);
|
||||||
|
|
||||||
|
// 🔍 Filtro nodi significativi: elimina tutti i nodi vuoti o whitespace
|
||||||
|
const nodes = rawNodes.filter(n => {
|
||||||
|
if (n.nodeType === 3) return n.nodeValue.trim() !== "";
|
||||||
|
return true; // elementi HTML validi
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`\n📦 [Cella ${cellIndex + 1}] Analizzo ${nodes.length} nodi validi...`);
|
||||||
|
const newContent = $('<div></div>');
|
||||||
|
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
const node = nodes[i];
|
||||||
|
|
||||||
|
// Se è un'icona <i>, cerca il contenuto associato
|
||||||
|
if (node.nodeType === 1 && node.tagName === "I") {
|
||||||
|
const $icon = $(node).clone();
|
||||||
|
const $row = $('<div class="gaia-line"></div>').css({
|
||||||
|
"display": "flex",
|
||||||
|
"align-items": "baseline",
|
||||||
|
"gap": "5px",
|
||||||
|
"line-height": "1.4",
|
||||||
|
"margin-bottom": "2px"
|
||||||
|
});
|
||||||
|
|
||||||
|
$icon.css({
|
||||||
|
"margin-right": "4px",
|
||||||
|
"vertical-align": "middle"
|
||||||
|
});
|
||||||
|
|
||||||
|
$row.append($icon);
|
||||||
|
|
||||||
|
// 🔄 Trova il prossimo nodo utile: testo o <a>
|
||||||
|
let content = null;
|
||||||
|
let nextIndex = i + 1;
|
||||||
|
|
||||||
|
while (nextIndex < nodes.length) {
|
||||||
|
const nextNode = nodes[nextIndex];
|
||||||
|
|
||||||
|
if (nextNode.nodeType === 3) {
|
||||||
|
const text = nextNode.nodeValue.trim();
|
||||||
|
if (text) {
|
||||||
|
content = $('<span></span>').text(text);
|
||||||
|
if (text.length > 40) {
|
||||||
|
content.css({
|
||||||
|
"display": "inline-block",
|
||||||
|
"max-width": "200px",
|
||||||
|
"white-space": "nowrap",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"text-overflow": "ellipsis",
|
||||||
|
"vertical-align": "middle"
|
||||||
|
}).attr("title", text);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (nextNode.nodeType === 1) {
|
||||||
|
const $el = $(nextNode);
|
||||||
|
|
||||||
|
if (nextNode.tagName === "A") {
|
||||||
|
// Gestione <a> (link)
|
||||||
|
let text = $el.text().trim();
|
||||||
|
|
||||||
|
if (!text) {
|
||||||
|
const href = $el.attr("href") || "";
|
||||||
|
const fallback = href.split("/").pop();
|
||||||
|
text = fallback || "(documento)";
|
||||||
|
$el.text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
$el.css({
|
||||||
|
"display": "inline-block",
|
||||||
|
"max-width": "200px",
|
||||||
|
"white-space": "nowrap",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"text-overflow": "ellipsis",
|
||||||
|
"vertical-align": "middle",
|
||||||
|
"color": "#a94442"
|
||||||
|
}).attr("title", text);
|
||||||
|
|
||||||
|
content = $el;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Gestione <span> (es. .monospace o altro)
|
||||||
|
else if (nextNode.tagName === "SPAN") {
|
||||||
|
const text = $el.text().trim();
|
||||||
|
if (text) {
|
||||||
|
content = $el.clone();
|
||||||
|
|
||||||
|
content.css({
|
||||||
|
"display": "inline-block",
|
||||||
|
"max-width": "200px",
|
||||||
|
"white-space": "nowrap",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"text-overflow": "ellipsis",
|
||||||
|
"vertical-align": "middle"
|
||||||
|
}).attr("title", text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = nextIndex - 1; // Salta i nodi già processati
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
$row.append(content);
|
||||||
|
newContent.append($row);
|
||||||
|
console.log(`✅ Riga generata: ${$icon.attr("class")} + contenuto`);
|
||||||
} else {
|
} else {
|
||||||
let script = document.createElement('script');
|
console.warn(`⚠️ Riga ignorata: icona "${$icon.attr("class")}" senza contenuto`);
|
||||||
script.src = 'https://code.jquery.com/jquery-3.6.0.min.js';
|
}
|
||||||
script.onload = () => callback(window.jQuery);
|
|
||||||
document.head.appendChild(script);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureJQuery(($) => {
|
$td.empty().append(newContent);
|
||||||
console.log("GAIA Swissknife: jQuery caricato con successo!");
|
});
|
||||||
|
}
|
||||||
function initScript() {
|
}
|
||||||
|
|
||||||
// Funzione per aggiungere il blocco di intestazione
|
// Funzione per aggiungere il blocco di intestazione
|
||||||
function ensureSwissknifeHeader() {
|
function ensureSwissknifeHeader() {
|
||||||
|
|
@ -183,22 +304,43 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funzione per evidenziare le righe con "Respinto"
|
// Funzione per evidenziare le righe con "Respinto" NON STA FUNZIONANDO
|
||||||
function highlightRejectedCourses() {
|
function highlightRejectedCourses() {
|
||||||
if (!window.location.href.match(/\/profilo\/\d+\/curriculum\//)) return;
|
if (!window.location.href.match(/\/profilo\/\d+\/curriculum\//)) return;
|
||||||
|
|
||||||
console.log("GAIA Swissknife: Cerco righe con 'Respinto'...");
|
console.log(`GAIA Swissknife: Qualifiche Rifiutate, rilevazione avviata..`);
|
||||||
|
|
||||||
$("tr").each(function() {
|
const $table = $(".table.table-striped");
|
||||||
const row = $(this);
|
if (!$table.length || !$.fn.DataTable.isDataTable($table)) return;
|
||||||
if (row.text().trim().includes("Respinto")) {
|
|
||||||
row.css("background-color", "#f8d7da");
|
const api = $table.DataTable();
|
||||||
row.css("border-left", "4px solid #dc3545"); // opzionale: bordo rosso
|
|
||||||
console.log("GAIA Swissknife: Riga evidenziata ->", row.text().trim().substring(0, 100));
|
function applyRejectionStyle() {
|
||||||
|
api.rows({ search: "applied" }).every(function (rowIdx, tableLoop, rowLoop) {
|
||||||
|
const $row = $(this.node());
|
||||||
|
const hasRespinto = $row.text().includes("Respinto");
|
||||||
|
|
||||||
|
if (hasRespinto) {
|
||||||
|
const nomeCorso = $row.find("p.grassetto").text().trim() || "Corso non trovato";
|
||||||
|
console.log(`🟥 Respinto trovato nella riga ${rowIdx + 1}: ${nomeCorso}`);
|
||||||
|
|
||||||
|
$row.css({
|
||||||
|
"box-shadow": "inset 8px 0 0 0 #dc3545",
|
||||||
|
"background-color": "#fbe9ea"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$row.css({
|
||||||
|
"box-shadow": "",
|
||||||
|
"background-color": ""
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyRejectionStyle();
|
||||||
|
$table.on("draw.dt", applyRejectionStyle);
|
||||||
|
}
|
||||||
|
|
||||||
// Funzione per aggiungere il tool per i profili delle richieste iscrizioni
|
// Funzione per aggiungere il tool per i profili delle richieste iscrizioni
|
||||||
function addAuthorizationProfileTool() {
|
function addAuthorizationProfileTool() {
|
||||||
if (!window.location.href.includes("/autorizzazioni/")) return;
|
if (!window.location.href.includes("/autorizzazioni/")) return;
|
||||||
|
|
@ -367,15 +509,69 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enhanceCurriculumTable() {
|
||||||
|
if (!window.location.href.match(/\/profilo\/\d+\/curriculum\//)) return;
|
||||||
|
|
||||||
|
const palette = {
|
||||||
|
"Qualifica CRI": "#e6f0ff", // blu chiaro
|
||||||
|
"Altra Qualifica": "#e6fff0", // verde chiaro
|
||||||
|
"Esperienze Professionali": "#fff3e6", // arancione chiaro
|
||||||
|
"Competenza Personale": "#e6faff", // ciano chiaro
|
||||||
|
"Patente Civile": "#f0f0f0", // grigio chiaro
|
||||||
|
"Patente CRI": "#f3e6ff" // lilla chiaro
|
||||||
|
};
|
||||||
|
|
||||||
|
const $table = $(".table.table-striped");
|
||||||
|
const $tbody = $table.find("tbody");
|
||||||
|
if (!$table.length || !$tbody.length) return;
|
||||||
|
|
||||||
|
console.log("GAIA Swissknife: DataTable + Colorazione permanente per tipologia...");
|
||||||
|
|
||||||
|
$table.DataTable({
|
||||||
|
paging: false,
|
||||||
|
order: [[0, 'asc'], [1, 'asc']],
|
||||||
|
columnDefs: [
|
||||||
|
{ orderable: false, targets: 3 }
|
||||||
|
],
|
||||||
|
language: {
|
||||||
|
search: "Filtra qualifiche:",
|
||||||
|
zeroRecords: "Nessuna qualifica trovata",
|
||||||
|
info: "Mostrate _TOTAL_ qualifiche",
|
||||||
|
infoEmpty: "Nessuna qualifica disponibile",
|
||||||
|
infoFiltered: "(filtrate da _MAX_ totali)"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function applyColoring() {
|
||||||
|
const tableApi = $table.DataTable();
|
||||||
|
tableApi.rows().every(function () {
|
||||||
|
const $row = $(this.node());
|
||||||
|
const $tipoCell = $row.find("td").eq(0);
|
||||||
|
const tipo = $tipoCell.text().trim();
|
||||||
|
|
||||||
|
if (palette[tipo]) {
|
||||||
|
$tipoCell.css("background-color", palette[tipo]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
applyColoring();
|
||||||
|
|
||||||
|
$table.on('draw.dt', function () {
|
||||||
|
// mantiene le celle pulite
|
||||||
|
applyStyleFixes();
|
||||||
|
// ricolora dopo ogni ricerca/ordinamento
|
||||||
|
applyColoring();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
|
applyStyleFixes();
|
||||||
addExamOutcomeButtons();
|
addExamOutcomeButtons();
|
||||||
addOpenAllProfilesButton();
|
addOpenAllProfilesButton();
|
||||||
highlightRejectedCourses();
|
highlightRejectedCourses();
|
||||||
addAuthorizationProfileTool();
|
addAuthorizationProfileTool();
|
||||||
|
enhanceCurriculumTable();
|
||||||
|
console.log("GAIA Swissknife: Funzioni caricate con successo!");
|
||||||
});
|
});
|
||||||
}
|
})(jQuery.noConflict(true));
|
||||||
|
|
||||||
initScript();
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue