// Icone de l'onglet : reprend le logo defini pour cette app dans l'admin // YunoHost (Applications > Home Page > logo), lu via /yunohost/portalapi/me. // Le dernier logo connu est garde dans le navigateur pour s'afficher tout de // suite au chargement suivant. "portal.favicon" dans config.json, s'il est // renseigne, a la priorite (voir app.js). (function () { const STORAGE_KEY = "homepage-favicon"; function setFavicon(href) { if (!href) return; let link = document.querySelector('link[rel="icon"]'); if (!link) { link = document.createElement("link"); link.rel = "icon"; document.head.appendChild(link); } if (link.href !== href) link.href = href; } function remember(href) { try { localStorage.setItem(STORAGE_KEY, href); } catch (e) { /* ignore */ } } function trimSlash(path) { return path.replace(/\/+$/, ""); } // Chemin de l'app = dossier de ce script (ex. /home pour /home/favicon.js), // qu'il soit charge par la page d'accueil ou par l'editeur (/home/edit/). const ownPath = trimSlash(new URL(".", document.currentScript.src).pathname); const ownKey = (window.location.host + ownPath).toLowerCase(); try { setFavicon(localStorage.getItem(STORAGE_KEY)); } catch (e) { /* ignore */ } window.homepageSetFavicon = function (href) { setFavicon(href); remember(href); }; fetch("/yunohost/portalapi/me", { credentials: "same-origin", cache: "no-store" }) .then((r) => (r.ok ? r.json() : null)) .then((me) => { if (!me || !me.apps || window.homepageFaviconOverride) return; const self = Object.values(me.apps).find((info) => { const url = trimSlash((info.url || "").replace(/^https?:\/\//, "")).toLowerCase(); return url === ownKey; }); if (self && self.logo) window.homepageSetFavicon(new URL(self.logo, window.location.origin).href); }) .catch(() => { /* hors YunoHost (apercu local) : pas de portail */ }); })();