From 53d1d508ba978f8cb98e7f65912b9346d27ec24a Mon Sep 17 00:00:00 2001 From: Clovis1444 Date: Sun, 18 Aug 2024 23:27:18 +0300 Subject: [PATCH] feat: fix button persistence after redirect; remove button padding --- manifest.json | 2 +- src/kpfb.js | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index c841365..4521a6e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "KPFB", - "version": "0.0.5", + "version": "0.0.6", "description": "Quick redirrect to Flickbar from Kinopoisk.", "browser_specific_settings": { "gecko": { diff --git a/src/kpfb.js b/src/kpfb.js index f75c63e..65d1117 100644 --- a/src/kpfb.js +++ b/src/kpfb.js @@ -74,12 +74,18 @@ class Kpfb { } static createButton() { + const button_id = "KPFB"; + + if (document.getElementById(button_id)) { + return; + } + // Button const kpfb_button = document.createElement("img"); - kpfb_button.id = "KPFB"; + kpfb_button.id = button_id; kpfb_button.style.width = "48px"; kpfb_button.style.height = "48px"; - kpfb_button.style.paddingRight = "10px"; + // kpfb_button.style.paddingRight = "10px"; kpfb_button.title = "Watch on Flicksbar"; const img = browser.runtime.getURL("icons/kpfb-48.png"); @@ -94,6 +100,19 @@ class Kpfb { function main() { Kpfb.createButton(); + + // To fix button persistence after redirect + // Create button after site redirecting + const observer = new MutationObserver(() => { + Kpfb.createButton(); + }); + observer.observe(document.body, { + childList: true, + subtree: true, + }); + + // Fallback for page navigation or if the page is dynamically updated + window.addEventListener("load", Kpfb.createButton); } // Call main()