feat(plugin): FixYoutubeEmbeds - fix UMG blocked embeds (#2116)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
~coolelectronics 2024-01-18 20:07:35 -05:00 committed by GitHub
parent 988435714e
commit 1670733458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# FixYoutubeEmbeds
Bypasses youtube videos being blocked from display on Discord (for example by UMG)
![](https://github.com/Vendicated/Vencord/assets/45497981/7a5fdcaa-217c-4c63-acae-f0d6af2f79be)

View file

@ -0,0 +1,14 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
export default definePlugin({
name: "FixYoutubeEmbeds",
description: "Bypasses youtube videos being blocked from display on Discord (for example by UMG)",
authors: [Devs.coolelectronics]
});

View file

@ -0,0 +1,26 @@
/*
* 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(() => {
let err = document.querySelector(".ytp-error-content-wrap-subreason span")?.textContent;
if (err && err.includes("blocked it from display")) window.location.reload()
}).observe(document.body, { childList: true, subtree:true });
`);
}
});
});
});

View file

@ -407,6 +407,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "Samwich",
id: 976176454511509554n,
},
coolelectronics: {
name: "coolelectronics",
id: 696392247205298207n,
}
} satisfies Record<string, Dev>);
// iife so #__PURE__ works correctly