Show images/video directly in chat!
Fra og med
// ==UserScript==
// @name BumScript
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Show images/video directly in chat!
// @author Bum
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @match https://www.twitch.tv/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var targetNode = document.getElementsByClassName('tw-flex')[0];
if (targetNode == undefined){
targetNode = document.getElementsByClassName('tw-absolute')[0];
}
// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
var callback = function(mutationsList, observer) {
for(var mutation of mutationsList) {
$(".link-fragment").each(function(){
if (($(this).text().indexOf(".jpg") > 0 ) || (($(this).text().indexOf(".png") > 0 )) || (($(this).text().indexOf(".gif") > 0 ))|| (($(this).text().indexOf(".jpeg") > 0 ))|| (($(this).text().indexOf(".webp") > 0 ))){
$(this).html("<img src='" + $(this).text() + "' width='200px'/>");
}
if ($(this).text().indexOf(".mp4") > 0 ){
$(this).html('<video width="320" height="240" controls autoplay><source src="'+ $(this).text() +'" type="video/mp4"></video>');
}
if ($(this).text().indexOf("www.youtube") > 0 ){
$(this).html('<iframe width="320" height="240" src="' + $(this).text().replace("watch?v=", "embed/") +'"></iframe>');
}
});
$(".text-fragment").each(function(){
if (($(this).text().indexOf(".jpg") > 0 ) || (($(this).text().indexOf(".png") > 0 )) || (($(this).text().indexOf(".gif") > 0 ))|| (($(this).text().indexOf(".jpeg") > 0 ))){
$(this).html("<img src='" + $(this).text() + "' width='200px'/>");
}
});
}
};
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
})();