1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-26 17:26:22 +00:00
Vencord/src/plugins/fixYoutubeEmbeds.desktop/native.ts
Klen_list 828688b996 fixYoutubeEmbeds: fix when youtube decides to use http without s (#2155)
Co-authored-by: V <vendicated@riseup.net>
2024-05-27 15:42:53 -04:00

27 lines
961 B
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { app } from "electron";
import { getSettings } from "main/ipcMain";
app.on("browser-window-created", (_, win) => {
win.webContents.on("frame-created", (_, { frame }) => {
frame.once("dom-ready", () => {
if (frame.url.startsWith("https://www.youtube.com/")) {
const settings = getSettings().plugins?.FixYoutubeEmbeds;
if (!settings?.enabled) return;
frame.executeJavaScript(`
new MutationObserver(() => {
if(
document.querySelector('div.ytp-error-content-wrap-subreason a[href*="www.youtube.com/watch?v="]')
) location.reload()
}).observe(document.body, { childList: true, subtree:true });
`);
}
});
});
});