Created
May 20, 2017 16:07
-
-
Save dvingerh/09d1ef8aa0dc4d01f4892ce1d54edc7c to your computer and use it in GitHub Desktop.
Discord Streamable Embed - Embed userscript for Streamable videos you can use until Discord fixes this issue.
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 Discord Streamable Embed | |
// @description Embed userscript for Streamable videos you can use until Discord fixes this issue. | |
// @namespace Discord Streamable Embed | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js | |
// @match *://discordapp.com/* | |
// | |
// ==/UserScript== | |
(function($) { | |
"use strict"; | |
$.fn.streamableMsg = function() { | |
$("div[class$='embed-link']").each( | |
function() { | |
if ($(this).is("#streamableFixed") === false && $(this).html().indexOf("streamable") !== -1) | |
{ | |
$(this).attr('id', 'streamableFixed'); | |
var videoWidth = $(this).find("a[class*='embed-thumbnail']").width() * 5; | |
var videoHeight = $(this).find("a[class*='embed-thumbnail']").height() * 5; | |
var link = $(this).find("a[class*='embed-thumbnail']").attr('href').replace("https://streamable.com/", "https://streamable.com/t/") + "?r=t"; | |
//alert(videoWidth + "x" + videoHeight + " for " + link); | |
//$(this).html('<video width="' + videoWidth + '" height="' + videoHeight + '" controls><source src="' + link + '" type="video/mp4"></video>'); | |
$(this).html('<iframe width="' + videoWidth + '" height="' + videoHeight + '" src="' + link + '"></iframe>'); | |
} | |
} | |
); | |
return this; | |
}; | |
// Helper function for finding all elements matching selector affected by a mutation | |
var mutationFind = function(mutation, selector) { | |
var target = $(mutation.target), | |
addedNodes = $(mutation.addedNodes); | |
var mutated = target.add(addedNodes).filter(selector); | |
var descendants = addedNodes.find(selector); | |
var ancestors = target.parents(selector); | |
return mutated.add(descendants).add(ancestors); | |
}; | |
// Watch for new messages in chat | |
new MutationObserver(function(mutations, observer) { | |
mutations.forEach(function(mutation) { | |
mutationFind(mutation, ".message").streamableMsg(); | |
}); | |
}).observe(document, { | |
childList: true, | |
subtree: true | |
}); | |
})(jQuery.noConflict(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment