diff --git a/plugin.js b/plugin.js index 4aa3437..f553056 100644 --- a/plugin.js +++ b/plugin.js @@ -389,37 +389,25 @@ } // ---------- Menu item ---------- - // Lampa builds the main menu on the 'menu:start' event, e.body is the jQuery menu root. - // Remove ALL old copies from the DOM first, then add exactly one button. - function makeButton() { - var button = $( - '' - ); - button.on('hover:enter', function () { - Lampa.Activity.push({ - url: '', - component: PLUGIN.name, - title: t(PLUGIN.title), - page: t(PLUGIN.title) - }); - }); - return button; - } - - var menuSubscribed = false; - function addMenuButton() { - // remove ALL copies everywhere in DOM, then add exactly one - $('[data-action="' + PLUGIN.menu_action + '"]').remove(); - $('.menu .menu__list').eq(0).append(makeButton()); - if (Lampa.Selector) Lampa.Selector.update(); - } + // Lampa builds the main menu on the 'menu:start' event. We add our item via the + // native Lampa.Menu.addButton() API (adds to .menu__list and wires hover:enter). var menuSubscribed = false; var menuInterval = null; + function addMenuButton() { + // Use Lampa's native menu API (adds to .menu__list:eq(0) and wires hover:enter). + Lampa.Menu.addButton( + '', + t(PLUGIN.title), + function () { + Lampa.Activity.push({ + url: '', + component: PLUGIN.name, + title: t(PLUGIN.title), + page: t(PLUGIN.title) + }); + } + ); + } function start() { if (menuSubscribed) return; menuSubscribed = true; @@ -449,7 +437,6 @@ // The main menu may already be built (or built later) by the time this plugin // loads. Poll briefly (every 500ms) until it appears, then add the item once. - // This keeps it from showing "late and shoving items" while still being reliable. if (!tryAdd()) { menuInterval = setInterval(tryAdd, 500); // safety: stop polling after 30s regardless