-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c09168e
commit 7f4c46f
Showing
4 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { PlasmoMessaging } from "@plasmohq/messaging" | ||
import type { RoomsList } from "~utils/rooms" | ||
import { Storage } from "@plasmohq/storage" | ||
import browser from "webextension-polyfill" | ||
|
||
const handler: PlasmoMessaging.MessageHandler = async (req, res) => { | ||
const tabs = await browser.tabs.query({ active: true, currentWindow: true }) | ||
|
||
const storage = new Storage({ area: "local" }) | ||
const rooms = await storage.get<RoomsList>("rooms") | ||
if (tabs[0].id && rooms[tabs[0].id]) res.send(true) | ||
res.send(false) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { PlasmoCSConfig } from "plasmo" | ||
import { sendToBackground } from "@plasmohq/messaging" | ||
// this cs reinjects automatically the main logic if a room has been created and no vides were found | ||
export const config: PlasmoCSConfig = { | ||
matches: ["<all_urls>"], | ||
all_frames: true | ||
} | ||
|
||
const observer = new MutationObserver((mutations) => { | ||
// check to reinject only if videos or iframes are added | ||
if ( | ||
mutations.some((mut) => | ||
Array.from(mut.addedNodes).some((node) => | ||
["VIDEO", "IFRAME"].includes(node.nodeName) | ||
) | ||
) | ||
) { | ||
console.log("injecting again") | ||
sendToBackground({ name: "shouldInject" }).then((res: boolean) => { | ||
console.log("shouldInject", res) | ||
if (res) sendToBackground({ name: "inject" }) | ||
}) | ||
} | ||
}) | ||
|
||
observer.observe(document, { subtree: true, childList: true }) | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const hasVideos = () => { | ||
return document.getElementsByTagName("video").length > 0 | ||
} |