Skip to content

Instantly share code, notes, and snippets.

@Neppu-Nep
Last active December 30, 2024 05:32
Show Gist options
  • Save Neppu-Nep/2aef7dffb6338fcaa6aa6be45d7db29f to your computer and use it in GitHub Desktop.
Save Neppu-Nep/2aef7dffb6338fcaa6aa6be45d7db29f to your computer and use it in GitHub Desktop.
Fixes for youtube embed issues (Membership embed not working, embed videos not resuming from where left off)
// ==UserScript==
// @name Youtube Embed Fixes
// @version 2024-12-30
// @description Temp fixes for youtube embed issues
// @author Nep
// @connect www.youtube.com
// @match https://www.youtube.com/embed/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @run-at document-start
// ==/UserScript==
function fixEmbed(oWriteEmbed) {
const ytID = window.location.pathname.match(/embed\/(.*)/)[1];
GM_xmlhttpRequest({
method: "GET",
url: `https://www.youtube.com/watch?v=${ytID}`,
headers: { "Content-Type": "application/json" },
onload: r => {
const ytInitialData = JSON.parse(r.responseText.split("var ytInitialPlayerResponse = ")[1].split(";var meta")[0]);
const statusVar = JSON.parse(unsafeWindow.ytcfg.data_.PLAYER_VARS.embedded_player_response);
unsafeWindow.ytcfg.data_.PLAYER_VARS.embedded_player_response = unsafeWindow.ytcfg.data_.PLAYER_VARS.player_response = JSON.stringify({
...statusVar,
playerConfig: {...ytInitialData.playerConfig},
videoDetails: {...ytInitialData.videoDetails},
previewPlayabilityStatus: { status: ytInitialData.playabilityStatus.status != "ERROR" ? "OK" : "ERROR" },
playabilityStatus: {...ytInitialData.playabilityStatus}
});
oWriteEmbed();
}
});
}
(function() {
'use strict';
Object.defineProperty(unsafeWindow, 'writeEmbed', {
get: () => unsafeWindow.writeEmbed_,
set: v => unsafeWindow.writeEmbed_ = () => fixEmbed(v)
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment