// Inject CSS once. injectStyle(cfg.style);
<script src="https://pastebin.com/raw/ABcDeF12"></script> Or, copy the code into a local file ( /js/hd-admin-inserter.js ) and reference it:
// ----------------------------------------------------------------- // 3️⃣ Helper: create a button element from an item definition. // ----------------------------------------------------------------- const createButton = (item) => ;
// Abort if visibilityFn says “nope”. if (!cfg.visibilityFn()) return;
// ----------------------------------------------------------------- // 6️⃣ Auto‑run on DOMContentLoaded (you can disable this by setting // `window.HD_ADMIN_NO_AUTO` before the script loads). // ----------------------------------------------------------------- if (!window.HD_ADMIN_NO_AUTO) document.addEventListener('DOMContentLoaded', () => mountToolbar());
// Append to the chosen mount point. const mountEl = document.querySelector(cfg.mountPoint); if (!mountEl) console.error('HD Admin Inserter: mount point not found:', cfg.mountPoint); return; mountEl.appendChild(toolbar); ;
<script src="/js/hd-admin-inserter.js"></script> If you are using a bundler, import '/js/hd-admin-inserter.js'; works just as well. 5.2. Ensure the user role is exposed The default visibilityFn looks for window.currentUser.role . Add something like:
// ----------------------------------------------------------------- // 4️⃣ Core: build and mount the toolbar. // ----------------------------------------------------------------- const mountToolbar = (config = {}) => const cfg = ...DEFAULT_CONFIG, ...config ;