diff --git a/tampermonkey-script/GAIA-Swissknife.user.js b/tampermonkey-script/GAIA-Swissknife.user.js index da27947..c6bec51 100644 --- a/tampermonkey-script/GAIA-Swissknife.user.js +++ b/tampermonkey-script/GAIA-Swissknife.user.js @@ -7,375 +7,571 @@ // @version 0.4.4-beta // @description Aggiunge funzionalità alle pagine di GAIA // @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 // ==/UserScript== -(function() { +GM_addStyle(GM_getResourceText("DataTablesCSS")); + +(function($) { 'use strict'; + console.log("GAIA Swissknife: Inizializzazione in corso!"); + // 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'; - // Controlla se jQuery è caricato, altrimenti lo carica - function ensureJQuery(callback) { - if (window.jQuery) { - callback(window.jQuery); - } else { - let script = document.createElement('script'); - script.src = 'https://code.jquery.com/jquery-3.6.0.min.js'; - script.onload = () => callback(window.jQuery); - document.head.appendChild(script); + function applyStyleFixes() { + const url = window.location.href; + + 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 = $('
'); + + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + + // Se è un'icona , cerca il contenuto associato + if (node.nodeType === 1 && node.tagName === "I") { + const $icon = $(node).clone(); + const $row = $('').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 + 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 = $('').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 (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 (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 { + console.warn(`⚠️ Riga ignorata: icona "${$icon.attr("class")}" senza contenuto`); + } + } + } + + $td.empty().append(newContent); + }); } } - ensureJQuery(($) => { - console.log("GAIA Swissknife: jQuery caricato con successo!"); + // Funzione per aggiungere il blocco di intestazione + function ensureSwissknifeHeader() { + if ($('#sezione').length > 0 && $('#gaia-swissknife-header').length === 0) { + const headerHTML = ` +