Skip to content

Commit

Permalink
feat: fix button persistence after redirect; remove button padding
Browse files Browse the repository at this point in the history
  • Loading branch information
Clovis1444 committed Aug 18, 2024
1 parent ee9f266 commit 53d1d50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
23 changes: 21 additions & 2 deletions src/kpfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()
Expand Down

0 comments on commit 53d1d50

Please sign in to comment.