summaryrefslogtreecommitdiff
path: root/inject/company-switcher.js
diff options
context:
space:
mode:
authormartin f. krafft <madduck@madduck.net>2025-06-26 16:08:32 +0200
committermartin f. krafft <madduck@madduck.net>2025-07-01 22:18:29 +0200
commitea8ce095f0e7ac61f31b79469d862df56f9d2bbc (patch)
tree81cdb69cfba9d1b661c7e9c76e335e9495a8466a /inject/company-switcher.js
parent4069c600b52213e01a727d786a6133435213bb43 (diff)
add favicons
Diffstat (limited to 'inject/company-switcher.js')
-rw-r--r--inject/company-switcher.js38
1 files changed, 36 insertions, 2 deletions
diff --git a/inject/company-switcher.js b/inject/company-switcher.js
index b491b8a..3861de5 100644
--- a/inject/company-switcher.js
+++ b/inject/company-switcher.js
@@ -35,11 +35,44 @@ export function registerObserver() {
// as cloning does not copy the event handlers
try {
let clone = elem.cloneNode(true);
- clone.attributes.toni = true
+ clone.attributes.toni = true // remember this for later
+ const cid = clone.getAttribute("data-company-id");
+
+ // Copy title and label from the checkbox child
+ const col1 = clone.childNodes[0];
+ const company = col1.getAttribute("aria-label");
+ const iscur = col1.getAttribute("aria-checked");
+ col1.removeAttribute("title");
+ col1.removeAttribute("aria-label");
+ col1.removeAttribute("aria-checked");
+ col1.removeAttribute("role");
+ col1.setAttribute("style", "width:42px");
+ if (iscur == "true") {
+ col1.classList.add("bg-primary-subtle");
+ }
+
+ clone.title = company;
+ clone.setAttribute("aria-label", company);
+ clone.setAttribute("aria-pressed", iscur);
+
+ const checkbox = col1.childNodes[0];
+ let img = document.createElement("img");
+ img.setAttribute("src", `/inject/${cid}/apple-touch-icon.png`);
+ img.setAttribute("class", "h-100 px-1");
+
+ col1.replaceChild(img, checkbox);
+
+ const col2 = clone.childNodes[1];
+ col2.removeAttribute("title");
+ col2.removeAttribute("aria-label");
+ col2.removeAttribute("aria-pressed");
+ col2.removeAttribute("role");
+
+ console.warn(clone);
+
clone.addEventListener('click', () => {
// … and we add our own event handler that opens a new window on the
// subdomain URL for the other company
- const cid = clone.attributes["data-company-id"].value;
const url = document.URL.replace(/:\/\/(\d+\.)?odoo/, `://${cid}.odoo`);
if (url) {
@@ -59,6 +92,7 @@ export function registerObserver() {
console.error("URL is empty, clone is:", clone);
}
});
+
elem.parentNode.replaceChild(clone, elem);
console.debug("Replaced with TONI clone:", clone);
} catch (e) { console.error("While cloning element:", elem, e); }