web: Extension shouldn't set options that are default

This commit is contained in:
Nathan Adams 2023-08-05 00:10:29 +02:00
parent 4f4dbc7973
commit ee1e8ec267
3 changed files with 23 additions and 2 deletions

View File

@ -108,6 +108,8 @@ function isXMLDocument(): boolean {
(async () => { (async () => {
const options = await utils.getOptions(); const options = await utils.getOptions();
const explicitOptions = await utils.getExplicitOptions();
const pageOptout = checkPageOptout(); const pageOptout = checkPageOptout();
const shouldLoad = const shouldLoad =
!isXMLDocument() && !isXMLDocument() &&
@ -171,7 +173,7 @@ function isXMLDocument(): boolean {
await sendMessageToPage({ await sendMessageToPage({
type: "load", type: "load",
config: { config: {
...options, ...explicitOptions,
autoplay: options.autostart ? "on" : "auto", autoplay: options.autostart ? "on" : "auto",
unmuteOverlay: options.autostart ? "hidden" : "visible", unmuteOverlay: options.autostart ? "hidden" : "visible",
splashScreen: !options.autostart, splashScreen: !options.autostart,

View File

@ -24,7 +24,7 @@ window.addEventListener("DOMContentLoaded", async () => {
player.id = "player"; player.id = "player";
document.getElementById("main")!.append(player); document.getElementById("main")!.append(player);
const options = await utils.getOptions(); const options = await utils.getExplicitOptions();
player.load({ player.load({
...options, ...options,

View File

@ -145,3 +145,22 @@ export async function getOptions(): Promise<Options> {
// Copy over default options if they don't exist yet. // Copy over default options if they don't exist yet.
return { ...DEFAULT_OPTIONS, ...options }; return { ...DEFAULT_OPTIONS, ...options };
} }
/**
* Gets the options that are explicitly different from the defaults.
*
* In the future we should just not store options we don't want to set.
*/
export async function getExplicitOptions(): Promise<Options> {
const options = await getOptions();
const defaultOptions = DEFAULT_OPTIONS;
for (const key in defaultOptions) {
// @ts-expect-error: Element implicitly has an any type
if (key in options && defaultOptions[key] === options[key]) {
// @ts-expect-error: Element implicitly has an any type
delete options[key];
}
}
return options;
}