fix
Cette révision appartient à :
1 Parent
de69a06e72
révision
31ed545928
1 file changed
+336
-72
+336
-72
@@ -1,320 +1,584 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
||||||
window.top !== window ||
|
window.top !== window ||
|
||||||
|
|
||||||
document.getElementById("skynet-sso-bar")
|
document.getElementById("skynet-sso-bar")
|
||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const allowed = await browser.runtime.sendMessage({
|
const allowed = await browser.runtime.sendMessage({
|
||||||
|
|
||||||
type: "SSO_IS_HOST_ALLOWED",
|
type: "SSO_IS_HOST_ALLOWED",
|
||||||
|
|
||||||
host: location.hostname
|
host: location.hostname
|
||||||
|
|
||||||
}).catch(() => false);
|
}).catch(() => false);
|
||||||
|
|
||||||
if (!allowed || document.getElementById("skynet-sso-bar")) {
|
if (!allowed || document.getElementById("skynet-sso-bar")) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefs = await browser.storage.local.get({
|
const prefs = await browser.storage.local.get({
|
||||||
|
|
||||||
showNotch: true
|
showNotch: true
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const bar = document.createElement("aside");
|
const bar = document.createElement("aside");
|
||||||
|
|
||||||
bar.id = "skynet-sso-bar";
|
bar.id = "skynet-sso-bar";
|
||||||
|
|
||||||
bar.dataset.collapsed = "false";
|
bar.dataset.collapsed = "false";
|
||||||
|
|
||||||
bar.dataset.showNotch = String(prefs.showNotch !== false);
|
bar.dataset.showNotch = String(prefs.showNotch !== false);
|
||||||
|
|
||||||
bar.setAttribute("aria-live", "polite");
|
bar.setAttribute("aria-live", "polite");
|
||||||
|
|
||||||
bar.innerHTML = `
|
// Build the toolbar with DOM methods instead of innerHTML.
|
||||||
<button
|
function createElement(tag, className, text) {
|
||||||
class="skynet-sso-brand"
|
const element = document.createElement(tag);
|
||||||
type="button"
|
if (className) element.className = className;
|
||||||
title="Accueil SKYNET"
|
if (text !== undefined) element.textContent = text;
|
||||||
>
|
return element;
|
||||||
<img
|
}
|
||||||
class="skynet-sso-mark"
|
|
||||||
src="${browser.runtime.getURL("icons/skynet.png")}"
|
|
||||||
alt=""
|
|
||||||
>
|
|
||||||
<span>SKYNET <b>SSO</b></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div class="skynet-sso-status">
|
const brand = createElement("button", "skynet-sso-brand");
|
||||||
<i></i>
|
brand.type = "button";
|
||||||
<span class="skynet-sso-label">Vérification de la session…</span>
|
brand.title = "Accueil SKYNET";
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="skynet-sso-user"></div>
|
const mark = createElement("img", "skynet-sso-mark");
|
||||||
|
mark.src = browser.runtime.getURL("icons/skynet.png");
|
||||||
|
mark.alt = "";
|
||||||
|
|
||||||
<div class="skynet-sso-actions">
|
const brandText = createElement("span");
|
||||||
<button class="skynet-sso-logout" type="button" hidden>
|
brandText.append("SKYNET ");
|
||||||
Déconnexion
|
brandText.appendChild(createElement("b", "", "SSO"));
|
||||||
</button>
|
brand.append(mark, brandText);
|
||||||
|
|
||||||
<button
|
const status = createElement("div", "skynet-sso-status");
|
||||||
class="skynet-sso-collapse"
|
status.appendChild(createElement("i"));
|
||||||
type="button"
|
status.appendChild(
|
||||||
aria-label="Masquer la barre SKYNET"
|
createElement("span", "skynet-sso-label", "Vérification de la session…")
|
||||||
title="Masquer la barre"
|
);
|
||||||
>
|
|
||||||
<span aria-hidden="true"></span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
const userElement = createElement("div", "skynet-sso-user");
|
||||||
class="skynet-sso-tab"
|
|
||||||
type="button"
|
const actions = createElement("div", "skynet-sso-actions");
|
||||||
aria-label="Afficher la barre SKYNET"
|
|
||||||
title="Afficher la barre"
|
const logoutButton = createElement("button", "skynet-sso-logout", "Déconnexion");
|
||||||
><span aria-hidden="true"></span></button>
|
logoutButton.type = "button";
|
||||||
`;
|
logoutButton.hidden = true;
|
||||||
|
|
||||||
|
const collapseButton = createElement("button", "skynet-sso-collapse");
|
||||||
|
collapseButton.type = "button";
|
||||||
|
collapseButton.setAttribute("aria-label", "Masquer la barre SKYNET");
|
||||||
|
collapseButton.title = "Masquer la barre";
|
||||||
|
collapseButton.appendChild(createElement("span"));
|
||||||
|
collapseButton.firstElementChild.setAttribute("aria-hidden", "true");
|
||||||
|
|
||||||
|
actions.append(logoutButton, collapseButton);
|
||||||
|
|
||||||
|
const tabButton = createElement("button", "skynet-sso-tab");
|
||||||
|
tabButton.type = "button";
|
||||||
|
tabButton.setAttribute("aria-label", "Afficher la barre SKYNET");
|
||||||
|
tabButton.title = "Afficher la barre";
|
||||||
|
const tabIcon = createElement("span");
|
||||||
|
tabIcon.setAttribute("aria-hidden", "true");
|
||||||
|
tabButton.appendChild(tabIcon);
|
||||||
|
|
||||||
|
bar.append(brand, status, userElement, actions, tabButton);
|
||||||
|
|
||||||
document.documentElement.appendChild(bar);
|
document.documentElement.appendChild(bar);
|
||||||
|
|
||||||
function collapseAfterPageLoad() {
|
function collapseAfterPageLoad() {
|
||||||
|
|
||||||
bar.dataset.collapsed = "true";
|
bar.dataset.collapsed = "true";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState === "complete") {
|
if (document.readyState === "complete") {
|
||||||
|
|
||||||
collapseAfterPageLoad();
|
collapseAfterPageLoad();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
window.addEventListener("load", collapseAfterPageLoad, { once: true });
|
window.addEventListener("load", collapseAfterPageLoad, { once: true });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialog = document.createElement("div");
|
const dialog = document.createElement("div");
|
||||||
|
|
||||||
dialog.id = "skynet-sso-dialog";
|
dialog.id = "skynet-sso-dialog";
|
||||||
dialog.innerHTML = `
|
|
||||||
<div class="skynet-sso-dialog-backdrop"></div>
|
// Build the logout dialog without parsing HTML strings.
|
||||||
<section
|
const backdrop = createElement("div", "skynet-sso-dialog-backdrop");
|
||||||
class="skynet-sso-dialog-panel"
|
|
||||||
role="dialog"
|
const dialogPanelElement = createElement("section", "skynet-sso-dialog-panel");
|
||||||
aria-modal="true"
|
dialogPanelElement.setAttribute("role", "dialog");
|
||||||
aria-labelledby="skynet-sso-dialog-title"
|
dialogPanelElement.setAttribute("aria-modal", "true");
|
||||||
aria-describedby="skynet-sso-dialog-description"
|
dialogPanelElement.setAttribute("aria-labelledby", "skynet-sso-dialog-title");
|
||||||
tabindex="-1"
|
dialogPanelElement.setAttribute(
|
||||||
>
|
"aria-describedby",
|
||||||
<div class="skynet-sso-dialog-symbol" aria-hidden="true">
|
"skynet-sso-dialog-description"
|
||||||
<span></span>
|
);
|
||||||
</div>
|
dialogPanelElement.tabIndex = -1;
|
||||||
<p class="skynet-sso-dialog-eyebrow">SKYNET SECURITY</p>
|
|
||||||
<h2 id="skynet-sso-dialog-title">Confirmer la déconnexion</h2>
|
const dialogSymbol = createElement("div", "skynet-sso-dialog-symbol");
|
||||||
<p id="skynet-sso-dialog-description">
|
dialogSymbol.setAttribute("aria-hidden", "true");
|
||||||
Souhaitez-vous vraiment fermer votre session SKYNET sur l’ensemble des services ?
|
dialogSymbol.appendChild(createElement("span"));
|
||||||
</p>
|
|
||||||
<p class="skynet-sso-dialog-error" role="alert" hidden></p>
|
const dialogEyebrow = createElement(
|
||||||
<div class="skynet-sso-dialog-progress" aria-live="polite" hidden>
|
"p",
|
||||||
<span class="skynet-sso-spinner" aria-hidden="true"></span>
|
"skynet-sso-dialog-eyebrow",
|
||||||
<span class="skynet-sso-dialog-progress-label">Déconnexion en cours…</span>
|
"SKYNET SECURITY"
|
||||||
</div>
|
);
|
||||||
<div class="skynet-sso-dialog-actions">
|
|
||||||
<button class="skynet-sso-dialog-cancel" type="button">Annuler</button>
|
const dialogTitle = createElement(
|
||||||
<button class="skynet-sso-dialog-confirm" type="button">
|
"h2",
|
||||||
<span>Me déconnecter</span>
|
"",
|
||||||
<span class="skynet-sso-dialog-arrow" aria-hidden="true">↗</span>
|
"Confirmer la déconnexion"
|
||||||
</button>
|
);
|
||||||
</div>
|
dialogTitle.id = "skynet-sso-dialog-title";
|
||||||
</section>
|
|
||||||
`;
|
const dialogDescriptionElement = createElement(
|
||||||
|
"p",
|
||||||
|
"",
|
||||||
|
"Souhaitez-vous vraiment fermer votre session SKYNET sur l’ensemble des services ?"
|
||||||
|
);
|
||||||
|
dialogDescriptionElement.id = "skynet-sso-dialog-description";
|
||||||
|
|
||||||
|
const dialogErrorElement = createElement("p", "skynet-sso-dialog-error");
|
||||||
|
dialogErrorElement.setAttribute("role", "alert");
|
||||||
|
dialogErrorElement.hidden = true;
|
||||||
|
|
||||||
|
const dialogProgressElement = createElement("div", "skynet-sso-dialog-progress");
|
||||||
|
dialogProgressElement.setAttribute("aria-live", "polite");
|
||||||
|
dialogProgressElement.hidden = true;
|
||||||
|
|
||||||
|
const spinner = createElement("span", "skynet-sso-spinner");
|
||||||
|
spinner.setAttribute("aria-hidden", "true");
|
||||||
|
|
||||||
|
const progressLabel = createElement(
|
||||||
|
"span",
|
||||||
|
"skynet-sso-dialog-progress-label",
|
||||||
|
"Déconnexion en cours…"
|
||||||
|
);
|
||||||
|
dialogProgressElement.append(spinner, progressLabel);
|
||||||
|
|
||||||
|
const dialogActions = createElement("div", "skynet-sso-dialog-actions");
|
||||||
|
|
||||||
|
const cancelButton = createElement(
|
||||||
|
"button",
|
||||||
|
"skynet-sso-dialog-cancel",
|
||||||
|
"Annuler"
|
||||||
|
);
|
||||||
|
cancelButton.type = "button";
|
||||||
|
|
||||||
|
const confirmButton = createElement("button", "skynet-sso-dialog-confirm");
|
||||||
|
confirmButton.type = "button";
|
||||||
|
confirmButton.append(
|
||||||
|
createElement("span", "", "Me déconnecter"),
|
||||||
|
createElement("span", "skynet-sso-dialog-arrow", "↗")
|
||||||
|
);
|
||||||
|
confirmButton.lastElementChild.setAttribute("aria-hidden", "true");
|
||||||
|
|
||||||
|
dialogActions.append(cancelButton, confirmButton);
|
||||||
|
|
||||||
|
dialogPanelElement.append(
|
||||||
|
dialogSymbol,
|
||||||
|
dialogEyebrow,
|
||||||
|
dialogTitle,
|
||||||
|
dialogDescriptionElement,
|
||||||
|
dialogErrorElement,
|
||||||
|
dialogProgressElement,
|
||||||
|
dialogActions
|
||||||
|
);
|
||||||
|
|
||||||
|
dialog.append(backdrop, dialogPanelElement);
|
||||||
|
|
||||||
document.documentElement.appendChild(dialog);
|
document.documentElement.appendChild(dialog);
|
||||||
|
|
||||||
const dialogPanel = dialog.querySelector(".skynet-sso-dialog-panel");
|
const dialogPanel = dialog.querySelector(".skynet-sso-dialog-panel");
|
||||||
|
|
||||||
const dialogCancel = dialog.querySelector(".skynet-sso-dialog-cancel");
|
const dialogCancel = dialog.querySelector(".skynet-sso-dialog-cancel");
|
||||||
|
|
||||||
const dialogConfirm = dialog.querySelector(".skynet-sso-dialog-confirm");
|
const dialogConfirm = dialog.querySelector(".skynet-sso-dialog-confirm");
|
||||||
|
|
||||||
const dialogError = dialog.querySelector(".skynet-sso-dialog-error");
|
const dialogError = dialog.querySelector(".skynet-sso-dialog-error");
|
||||||
|
|
||||||
const dialogProgress = dialog.querySelector(".skynet-sso-dialog-progress");
|
const dialogProgress = dialog.querySelector(".skynet-sso-dialog-progress");
|
||||||
|
|
||||||
const dialogProgressLabel = dialog.querySelector(".skynet-sso-dialog-progress-label");
|
const dialogProgressLabel = dialog.querySelector(".skynet-sso-dialog-progress-label");
|
||||||
|
|
||||||
const dialogDescription = dialog.querySelector("#skynet-sso-dialog-description");
|
const dialogDescription = dialog.querySelector("#skynet-sso-dialog-description");
|
||||||
|
|
||||||
function closeLogoutDialog() {
|
function closeLogoutDialog() {
|
||||||
|
|
||||||
if (dialog.dataset.busy === "true") return;
|
if (dialog.dataset.busy === "true") return;
|
||||||
|
|
||||||
dialog.dataset.open = "false";
|
dialog.dataset.open = "false";
|
||||||
|
|
||||||
dialogError.hidden = true;
|
dialogError.hidden = true;
|
||||||
|
|
||||||
logout.focus();
|
logout.focus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openLogoutDialog() {
|
function openLogoutDialog() {
|
||||||
|
|
||||||
dialog.dataset.open = "true";
|
dialog.dataset.open = "true";
|
||||||
|
|
||||||
dialog.dataset.busy = "false";
|
dialog.dataset.busy = "false";
|
||||||
|
|
||||||
dialogError.hidden = true;
|
dialogError.hidden = true;
|
||||||
|
|
||||||
dialogProgress.hidden = true;
|
dialogProgress.hidden = true;
|
||||||
|
|
||||||
dialogDescription.hidden = false;
|
dialogDescription.hidden = false;
|
||||||
|
|
||||||
dialogConfirm.disabled = false;
|
dialogConfirm.disabled = false;
|
||||||
|
|
||||||
dialogCancel.disabled = false;
|
dialogCancel.disabled = false;
|
||||||
|
|
||||||
dialogConfirm.querySelector("span").textContent = "Me déconnecter";
|
dialogConfirm.querySelector("span").textContent = "Me déconnecter";
|
||||||
|
|
||||||
dialogPanel.focus();
|
dialogPanel.focus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLogoutBusy(busy) {
|
function setLogoutBusy(busy) {
|
||||||
|
|
||||||
dialog.dataset.busy = String(busy);
|
dialog.dataset.busy = String(busy);
|
||||||
|
|
||||||
dialogProgress.hidden = !busy;
|
dialogProgress.hidden = !busy;
|
||||||
|
|
||||||
dialogDescription.hidden = busy;
|
dialogDescription.hidden = busy;
|
||||||
|
|
||||||
dialogCancel.disabled = busy;
|
dialogCancel.disabled = busy;
|
||||||
|
|
||||||
dialogConfirm.disabled = busy;
|
dialogConfirm.disabled = busy;
|
||||||
|
|
||||||
dialogConfirm.querySelector("span").textContent = busy
|
dialogConfirm.querySelector("span").textContent = busy
|
||||||
|
|
||||||
? "Déconnexion…"
|
? "Déconnexion…"
|
||||||
|
|
||||||
: "Me déconnecter";
|
: "Me déconnecter";
|
||||||
|
|
||||||
dialogProgressLabel.textContent = "Déconnexion en cours…";
|
dialogProgressLabel.textContent = "Déconnexion en cours…";
|
||||||
|
|
||||||
dialogError.hidden = true;
|
dialogError.hidden = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogCancel.addEventListener("click", closeLogoutDialog);
|
dialogCancel.addEventListener("click", closeLogoutDialog);
|
||||||
|
|
||||||
dialog.querySelector(".skynet-sso-dialog-backdrop")
|
dialog.querySelector(".skynet-sso-dialog-backdrop")
|
||||||
|
|
||||||
.addEventListener("click", closeLogoutDialog);
|
.addEventListener("click", closeLogoutDialog);
|
||||||
|
|
||||||
dialogConfirm.addEventListener("click", async () => {
|
dialogConfirm.addEventListener("click", async () => {
|
||||||
|
|
||||||
if (dialog.dataset.busy === "true") return;
|
if (dialog.dataset.busy === "true") return;
|
||||||
|
|
||||||
setLogoutBusy(true);
|
setLogoutBusy(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const result = await browser.runtime.sendMessage({
|
const result = await browser.runtime.sendMessage({
|
||||||
|
|
||||||
type: "SSO_LOGOUT"
|
type: "SSO_LOGOUT"
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result?.success) {
|
if (!result?.success) {
|
||||||
|
|
||||||
throw new Error("Le serveur n’a pas confirmé la déconnexion.");
|
throw new Error("Le serveur n’a pas confirmé la déconnexion.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogProgressLabel.textContent = "Session fermée. Actualisation…";
|
dialogProgressLabel.textContent = "Session fermée. Actualisation…";
|
||||||
|
|
||||||
render({ status: "anonymous" });
|
render({ status: "anonymous" });
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
dialog.dataset.busy = "false";
|
dialog.dataset.busy = "false";
|
||||||
|
|
||||||
dialogProgress.hidden = true;
|
dialogProgress.hidden = true;
|
||||||
|
|
||||||
dialogDescription.hidden = false;
|
dialogDescription.hidden = false;
|
||||||
|
|
||||||
dialogCancel.disabled = false;
|
dialogCancel.disabled = false;
|
||||||
|
|
||||||
dialogConfirm.disabled = false;
|
dialogConfirm.disabled = false;
|
||||||
|
|
||||||
dialogConfirm.querySelector("span").textContent = "Réessayer";
|
dialogConfirm.querySelector("span").textContent = "Réessayer";
|
||||||
|
|
||||||
dialogError.textContent = error.message || "La déconnexion a échoué. Veuillez réessayer.";
|
dialogError.textContent = error.message || "La déconnexion a échoué. Veuillez réessayer.";
|
||||||
|
|
||||||
dialogError.hidden = false;
|
dialogError.hidden = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("keydown", event => {
|
document.addEventListener("keydown", event => {
|
||||||
|
|
||||||
if (dialog.dataset.open !== "true") return;
|
if (dialog.dataset.open !== "true") return;
|
||||||
|
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
closeLogoutDialog();
|
closeLogoutDialog();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Tab") {
|
if (event.key === "Tab") {
|
||||||
|
|
||||||
const focusable = [dialogCancel, dialogConfirm].filter(
|
const focusable = [dialogCancel, dialogConfirm].filter(
|
||||||
|
|
||||||
element => !element.disabled
|
element => !element.disabled
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!focusable.length) {
|
if (!focusable.length) {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const first = focusable[0];
|
const first = focusable[0];
|
||||||
|
|
||||||
const last = focusable[focusable.length - 1];
|
const last = focusable[focusable.length - 1];
|
||||||
|
|
||||||
if (event.shiftKey && document.activeElement === first) {
|
if (event.shiftKey && document.activeElement === first) {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
last.focus();
|
last.focus();
|
||||||
|
|
||||||
} else if (!event.shiftKey && document.activeElement === last) {
|
} else if (!event.shiftKey && document.activeElement === last) {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
first.focus();
|
first.focus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const label = bar.querySelector(".skynet-sso-label");
|
const label = bar.querySelector(".skynet-sso-label");
|
||||||
|
|
||||||
const user = bar.querySelector(".skynet-sso-user");
|
const user = bar.querySelector(".skynet-sso-user");
|
||||||
|
|
||||||
const logout = bar.querySelector(".skynet-sso-logout");
|
const logout = bar.querySelector(".skynet-sso-logout");
|
||||||
|
|
||||||
const tab = bar.querySelector(".skynet-sso-tab");
|
const tab = bar.querySelector(".skynet-sso-tab");
|
||||||
|
|
||||||
const collapse = bar.querySelector(".skynet-sso-collapse");
|
const collapse = bar.querySelector(".skynet-sso-collapse");
|
||||||
const brand = bar.querySelector(".skynet-sso-brand");
|
|
||||||
|
|
||||||
brand.addEventListener("click", async event => {
|
brand.addEventListener("click", async event => {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
const cfg = await browser.storage.local.get({
|
const cfg = await browser.storage.local.get({
|
||||||
|
|
||||||
homeUrl: "https://celjim.fr"
|
homeUrl: "https://celjim.fr"
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const destination = String(
|
const destination = String(
|
||||||
|
|
||||||
cfg.homeUrl || "https://git.celjim.fr/public/zoraxy-sso-extension-firefox"
|
cfg.homeUrl || "https://git.celjim.fr/public/zoraxy-sso-extension-firefox"
|
||||||
|
|
||||||
).trim();
|
).trim();
|
||||||
|
|
||||||
if (/^https?:\/\//i.test(destination)) {
|
if (/^https?:\/\//i.test(destination)) {
|
||||||
|
|
||||||
window.location.assign(destination);
|
window.location.assign(destination);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("click", event => {
|
document.addEventListener("click", event => {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
||||||
bar.dataset.collapsed !== "true" &&
|
bar.dataset.collapsed !== "true" &&
|
||||||
|
|
||||||
!bar.contains(event.target)
|
!bar.contains(event.target)
|
||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
bar.dataset.collapsed = "true";
|
bar.dataset.collapsed = "true";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
let autoCollapseTimer = null;
|
||||||
|
|
||||||
|
function clearAutoCollapse() {
|
||||||
|
if (autoCollapseTimer !== null) {
|
||||||
|
window.clearTimeout(autoCollapseTimer);
|
||||||
|
autoCollapseTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleAutoCollapse() {
|
||||||
|
clearAutoCollapse();
|
||||||
|
autoCollapseTimer = window.setTimeout(() => {
|
||||||
|
bar.dataset.collapsed = "true";
|
||||||
|
autoCollapseTimer = null;
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
function revealBar(event) {
|
function revealBar(event) {
|
||||||
|
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
|
|
||||||
event?.stopPropagation();
|
event?.stopPropagation();
|
||||||
|
|
||||||
bar.dataset.collapsed = "false";
|
bar.dataset.collapsed = "false";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tout clic dans la barre annule le repli automatique.
|
// Tout clic dans la barre annule le repli automatique.
|
||||||
|
|
||||||
// Le clic sur l'encoche reste une action d'ouverture.
|
// Le clic sur l'encoche reste une action d'ouverture.
|
||||||
|
|
||||||
bar.addEventListener("click", event => {
|
bar.addEventListener("click", event => {
|
||||||
|
|
||||||
if (!tab.contains(event.target)) {
|
if (!tab.contains(event.target)) {
|
||||||
|
|
||||||
clearAutoCollapse();
|
clearAutoCollapse();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Repli manuel
|
// Repli manuel
|
||||||
|
|
||||||
collapse.addEventListener("click", event => {
|
collapse.addEventListener("click", event => {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
clearAutoCollapse();
|
clearAutoCollapse();
|
||||||
|
|
||||||
bar.dataset.collapsed = "true";
|
bar.dataset.collapsed = "true";
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Déploiement au survol ou au clic de l'encoche
|
// Déploiement au survol ou au clic de l'encoche
|
||||||
|
|
||||||
|
// L'encoche révèle la barre au survol, sans lancer de minuterie.
|
||||||
|
// La barre ne se replie automatiquement qu'après que le pointeur l'a quittée.
|
||||||
|
bar.addEventListener("mouseenter", clearAutoCollapse);
|
||||||
|
|
||||||
|
bar.addEventListener("mouseleave", () => {
|
||||||
|
if (bar.dataset.collapsed !== "true") {
|
||||||
|
scheduleAutoCollapse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
tab.addEventListener("mouseenter", revealBar);
|
tab.addEventListener("mouseenter", revealBar);
|
||||||
tab.addEventListener("click", revealBar);
|
|
||||||
|
tab.addEventListener("click", event => {
|
||||||
|
clearAutoCollapse();
|
||||||
|
revealBar(event);
|
||||||
|
});
|
||||||
|
|
||||||
function render(state) {
|
function render(state) {
|
||||||
|
|
||||||
bar.dataset.state = state.status;
|
bar.dataset.state = state.status;
|
||||||
|
|
||||||
user.textContent = state.username || "";
|
user.textContent = state.username || "";
|
||||||
|
|
||||||
logout.hidden = state.status !== "authenticated";
|
logout.hidden = state.status !== "authenticated";
|
||||||
|
|
||||||
if (state.status === "authenticated") {
|
if (state.status === "authenticated") {
|
||||||
|
|
||||||
label.textContent = "Session SSO active";
|
label.textContent = "Session SSO active";
|
||||||
|
|
||||||
} else if (state.status === "anonymous") {
|
} else if (state.status === "anonymous") {
|
||||||
|
|
||||||
label.textContent = "Aucune session SSO";
|
label.textContent = "Aucune session SSO";
|
||||||
|
|
||||||
} else if (state.status === "unavailable") {
|
} else if (state.status === "unavailable") {
|
||||||
|
|
||||||
label.textContent = "Serveur SSO indisponible";
|
label.textContent = "Serveur SSO indisponible";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
label.textContent = "Vérification de la session…";
|
label.textContent = "Vérification de la session…";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
|
|
||||||
type: "SSO_GET_STATE"
|
type: "SSO_GET_STATE"
|
||||||
|
|
||||||
}).then(render).catch(() => {
|
}).then(render).catch(() => {
|
||||||
|
|
||||||
render({ status: "unavailable" });
|
render({ status: "unavailable" });
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(message => {
|
browser.runtime.onMessage.addListener(message => {
|
||||||
|
|
||||||
if (message?.type === "SSO_STATE") {
|
if (message?.type === "SSO_STATE") {
|
||||||
|
|
||||||
render(message.state);
|
render(message.state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.storage.onChanged.addListener((changes, area) => {
|
browser.storage.onChanged.addListener((changes, area) => {
|
||||||
|
|
||||||
if (area === "local" && changes.showNotch) {
|
if (area === "local" && changes.showNotch) {
|
||||||
|
|
||||||
bar.dataset.showNotch = String(
|
bar.dataset.showNotch = String(
|
||||||
|
|
||||||
changes.showNotch.newValue !== false
|
changes.showNotch.newValue !== false
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logout.addEventListener("click", event => {
|
logout.addEventListener("click", event => {
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
openLogoutDialog();
|
openLogoutDialog();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur