debug(plugin): add console logging to svrnty_nav.js to diagnose silent injection failure
Some checks failed
plugin-tests / test (push) Failing after 5s
Some checks failed
plugin-tests / test (push) Failing after 5s
This commit is contained in:
parent
80420e0d01
commit
7a5c48c775
@ -11,6 +11,9 @@
|
||||
"use strict";
|
||||
if (window.__svrntyNavLoaded) return;
|
||||
window.__svrntyNavLoaded = true;
|
||||
const LOG = (...a) => console.log("[svrnty-nav]", ...a);
|
||||
const ERR = (...a) => console.error("[svrnty-nav]", ...a);
|
||||
LOG("loaded", { readyState: document.readyState });
|
||||
|
||||
const TABS = [
|
||||
{
|
||||
@ -31,9 +34,14 @@
|
||||
|
||||
function _injectButtons() {
|
||||
const nav = document.querySelector(".sidebar-nav");
|
||||
if (!nav) return false;
|
||||
if (!nav) {
|
||||
LOG("_injectButtons: .sidebar-nav not found yet");
|
||||
return false;
|
||||
}
|
||||
let added = 0;
|
||||
TABS.forEach((t) => {
|
||||
if (nav.querySelector('[data-panel="' + t.id + '"]')) return;
|
||||
try {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "nav-tab has-tooltip has-tooltip--bottom svrnty-nav-tab";
|
||||
btn.setAttribute("data-panel", t.id);
|
||||
@ -42,12 +50,20 @@
|
||||
btn.setAttribute("aria-label", t.label);
|
||||
btn.innerHTML = t.svg;
|
||||
btn.addEventListener("click", () => {
|
||||
LOG("button clicked:", t.id);
|
||||
if (typeof window.switchPanel === "function") {
|
||||
window.switchPanel(t.id, { fromRailClick: true });
|
||||
} else {
|
||||
ERR("switchPanel is not a function — cannot route click");
|
||||
}
|
||||
});
|
||||
nav.appendChild(btn);
|
||||
added++;
|
||||
} catch (e) {
|
||||
ERR("failed to inject button", t.id, e);
|
||||
}
|
||||
});
|
||||
LOG("_injectButtons: added", added, "of", TABS.length, "(nav children:", nav.children.length, ")");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -81,13 +97,20 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
let _initAttempts = 0;
|
||||
function _init() {
|
||||
_initAttempts++;
|
||||
const buttonsOk = _injectButtons();
|
||||
const wrapOk = _wrapSwitchPanel();
|
||||
if (!buttonsOk || !wrapOk) {
|
||||
// DOM not ready yet — retry on next paint
|
||||
if (_initAttempts < 100) {
|
||||
requestAnimationFrame(_init);
|
||||
} else {
|
||||
ERR("_init gave up after", _initAttempts, "attempts. buttonsOk=", buttonsOk, "wrapOk=", wrapOk);
|
||||
}
|
||||
return;
|
||||
}
|
||||
LOG("_init completed in", _initAttempts, "attempt(s)");
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user