mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
"use strict";
|
|
|
|
import { CAST_LOADER_SCRIPT_URL, CAST_SCRIPT_URLS } from "../lib/endpoints";
|
|
|
|
const _window = window.wrappedJSObject as any;
|
|
|
|
_window.chrome = cloneInto({}, window);
|
|
|
|
/**
|
|
* YouTube won't load the cast SDK unless it thinks the
|
|
* presentation API exists.
|
|
*/
|
|
if (window.location.host === "www.youtube.com") {
|
|
_window.navigator.presentation = cloneInto({}, window);
|
|
}
|
|
|
|
/**
|
|
* Replace the src property setter on <script> elements to
|
|
* intercept the new value.
|
|
*
|
|
* If it matches one of Chrome's cast extension sender script
|
|
* URLs, replace it with the standard API URL, the request for
|
|
* which is handled in the main script.
|
|
*/
|
|
const desc = Reflect.getOwnPropertyDescriptor(
|
|
HTMLScriptElement.prototype.wrappedJSObject,
|
|
"src"
|
|
);
|
|
|
|
Reflect.defineProperty(HTMLScriptElement.prototype.wrappedJSObject, "src", {
|
|
configurable: true,
|
|
enumerable: true,
|
|
get: desc?.get,
|
|
|
|
set: exportFunction(function setFunc(this: HTMLScriptElement, value) {
|
|
if (CAST_SCRIPT_URLS.includes(value)) {
|
|
return desc?.set?.call(this, CAST_LOADER_SCRIPT_URL);
|
|
}
|
|
|
|
return desc?.set?.call(this, value);
|
|
}, window)
|
|
});
|