FixYTEmbeds: This Fix Sucks
This commit is contained in:
parent
4f5935be9b
commit
ac439b6207
2 changed files with 7 additions and 16 deletions
|
|
@ -29,6 +29,7 @@ export default definePlugin({
|
|||
description: "Bypasses youtube videos being blocked from display on Discord (for example by UMG)",
|
||||
tags: ["Media", "Utility"],
|
||||
authors: [Devs.coolelectronics, Devs.arHSM],
|
||||
isModified: true,
|
||||
settings,
|
||||
patches: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,23 +5,13 @@
|
|||
*/
|
||||
|
||||
import { RendererSettings } from "@main/settings";
|
||||
import { app } from "electron";
|
||||
import { app, session } from "electron";
|
||||
|
||||
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 = RendererSettings.store.plugins?.FixYoutubeEmbeds;
|
||||
if (!settings?.enabled) return;
|
||||
app.whenReady().then(() => {
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders({ urls: ["https://www.youtube.com/embed/*"] }, ({ requestHeaders, resourceType }, callback) => {
|
||||
if (resourceType === "subFrame" && RendererSettings.store.plugins?.FixYoutubeEmbeds?.enabled)
|
||||
requestHeaders.Referer = "https://media.discordapp.com/";
|
||||
|
||||
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 });
|
||||
`);
|
||||
}
|
||||
});
|
||||
callback({ requestHeaders });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue