mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Dynamically register media overlay content script
This commit is contained in:
@@ -44,6 +44,8 @@ browser.runtime.onInstalled.addListener(async details => {
|
|||||||
|
|
||||||
|
|
||||||
function initBrowserAction () {
|
function initBrowserAction () {
|
||||||
|
console.info("fx_cast (Debug): init (browser action)");
|
||||||
|
|
||||||
/*browser.browserAction.disable();
|
/*browser.browserAction.disable();
|
||||||
|
|
||||||
function onServiceChange () {
|
function onServiceChange () {
|
||||||
@@ -504,6 +506,46 @@ function initWhitelist () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function initMediaOverlay () {
|
||||||
|
console.info("fx_cast (Debug): init (media overlay)");
|
||||||
|
|
||||||
|
let contentScript: browser.contentScripts.RegisteredContentScript;
|
||||||
|
|
||||||
|
async function registerMediaOverlayContentScript () {
|
||||||
|
if (!(await options.get("mediaOverlayEnabled"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
contentScript = await browser.contentScripts.register({
|
||||||
|
allFrames: true
|
||||||
|
, js: [{ file: "senders/media/overlay/overlayContentLoader.js" }]
|
||||||
|
, matches: [ "<all_urls>" ]
|
||||||
|
, runAt: "document_start"
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("fx_cast (Debug): Failed to register media overlay");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unregisterMediaOverlayContentScript () {
|
||||||
|
contentScript?.unregister();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
registerMediaOverlayContentScript();
|
||||||
|
|
||||||
|
options.addEventListener("changed", ev => {
|
||||||
|
const alteredOpts = ev.detail;
|
||||||
|
|
||||||
|
if (alteredOpts.includes("mediaOverlayEnabled")) {
|
||||||
|
unregisterMediaOverlayContentScript();
|
||||||
|
registerMediaOverlayContentScript();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
|
|
||||||
async function init () {
|
async function init () {
|
||||||
@@ -528,6 +570,7 @@ async function init () {
|
|||||||
await initMenus();
|
await initMenus();
|
||||||
await initRequestListener();
|
await initRequestListener();
|
||||||
await initWhitelist();
|
await initWhitelist();
|
||||||
|
await initMediaOverlay();
|
||||||
|
|
||||||
await StatusManager.init();
|
await StatusManager.init();
|
||||||
await ShimManager.init();
|
await ShimManager.init();
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
"all_frames": true
|
"all_frames": true
|
||||||
, "js": [
|
, "js": [
|
||||||
"shim/content.js"
|
"shim/content.js"
|
||||||
//, "senders/media/overlay/overlayContentLoader.js"
|
|
||||||
]
|
]
|
||||||
, "matches": [ "<all_urls>" ]
|
, "matches": [ "<all_urls>" ]
|
||||||
, "run_at": "document_start"
|
, "run_at": "document_start"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const _ = browser.i18n.getMessage;
|
|||||||
const req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
req.open("GET", browser.runtime.getURL(
|
req.open("GET", browser.runtime.getURL(
|
||||||
"senders/media/overlay/overlayContent.js"), false);
|
"senders/media/overlay/overlayContent.js"), false);
|
||||||
|
|
||||||
req.send();
|
req.send();
|
||||||
|
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
|
|||||||
Reference in New Issue
Block a user