Created
April 14, 2021 12:41
-
-
Save ItsCinnabar/ebcfe4f6b3ea7d224a8e1ef0783edeb2 to your computer and use it in GitHub Desktop.
Element youtube preview fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Element youtube preview | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description fix the embeds!! | |
// @author Cinnabar | |
// @match https:// url here .com | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant GM.xmlHttpRequest | |
// @connect youtube.com | |
// @connect youtu.be | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function previewEditor() { | |
const allPreviews = document.getElementsByClassName('mx_LinkPreviewWidget_caption'); | |
for (const preview of allPreviews) { | |
const linkTitle = preview.childNodes[0].children[0]; | |
const linkDesc = preview.childNodes[2] | |
if (linkTitle.text != "Before you continue to YouTube") { | |
continue | |
} | |
GM.xmlHttpRequest({ | |
method: "GET", | |
url: linkTitle.href, | |
onload: function(response) { | |
if (response.status == 200){ | |
const title = response.responseText.match(/<title[^>]*>([^<]+)<\/title>/)[1]; | |
const desc = response.responseText.match(/<meta name="description" content="(.*?)">/)[1]; | |
linkTitle.text = title | |
linkDesc.textContent = desc | |
} | |
} | |
}); | |
} | |
} | |
setInterval(previewEditor,2000); | |
})(); |
Thanks for the script ❤️
I modified it to use Youtube's oEmbed API: https://gist.github.com/cketti/edbf7efe5e641792d56a384dc501ba1e
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah that fixed it, got it working now! thank you guys so much <3