Skip to content

Commit

Permalink
fix whitelist issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alganzory committed Mar 22, 2024
1 parent 72e0936 commit 6ab2465
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
attachObserversListener,
initMutationObserver,
killObserver,
} from "./modules/observers";
import Settings from "./modules/settings";
import { attachStyleListener } from "./modules/style";
Expand All @@ -20,12 +21,25 @@ const attachAllListeners = () => {

if (window.self === window.top) {
attachAllListeners();
makeVideoFramePort('/src/offscreen.html').then((port) => {
initMutationObserver(port);
});

Settings.init()
.then((settings) => {
if (
settings
.getWhitelist()
.includes(
window.location.hostname?.split("www.")?.[1] ??
window.location.hostname
)
) {
console.log("HB==WHITELISTED SITE");
killObserver();
return;
}

makeVideoFramePort("/src/offscreen.html").then((port) => {
initMutationObserver(port);
});

// turn on/off the extension
settings.toggleOnOffStatus();
})
Expand All @@ -34,7 +48,6 @@ if (window.self === window.top) {
});
}


async function makeVideoFramePort(path) {
const secret = Math.random().toString(36);
const url = new URL(chrome.runtime.getURL(path));
Expand Down
7 changes: 6 additions & 1 deletion src/modules/observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const attachObserversListener = () => {
});
};

const killObserver = () => {
mutationObserver?.disconnect();
mutationObserver = null;
};

function observeNode(node, srcAttribute) {
const isVideo = node.tagName === "VIDEO";
if (
Expand Down Expand Up @@ -137,4 +142,4 @@ function observeNode(node, srcAttribute) {
}
}

export { attachObserversListener, initMutationObserver, STATUSES };
export { attachObserversListener, initMutationObserver, STATUSES, killObserver };

0 comments on commit 6ab2465

Please sign in to comment.