diff options
Diffstat (limited to 'inject/company-switcher.js')
| -rw-r--r-- | inject/company-switcher.js | 38 |
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); } |
