-
-
Save bertiebaggio/9ffe0e6e54d903c3be82cb2137aa5b3b to your computer and use it in GitHub Desktop.
Element youtube preview fix
This file contains 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.2 | |
// @description fix the embeds!! | |
// @author Cinnabar (bertieb for images) | |
// @match https://example.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'); | |
const allPreviews = document.getElementsByClassName('mx_LinkPreviewWidget'); | |
for (const preview of allPreviews) { | |
const previewImg = preview.childNodes[0].children[0]; | |
const caption = preview.childNodes[1]; | |
const linkTitle = caption.childNodes[0].children[0]; | |
const linkDesc = caption.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]; | |
const imgsrc = response.responseText.match(/<meta property="og:image" content="(.*?)">/)[1]; | |
linkTitle.text = title | |
linkDesc.textContent = desc | |
previewImg.src = imgsrc; | |
} | |
} | |
}); | |
} | |
} | |
setInterval(previewEditor,2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As noted in the original gist, remember to update the
@match
line with the URL of your Element client -- eg// @match https://app.element.io
-- and refresh the page after saving/enabling the script.