BumScript

Show images/video directly in chat!

Fra og med 13.12.2018. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
})();