Kmc / Reddit Replace Iframe

// ==UserScript==
// @name         Reddit Replace Iframe
// @namespace    kmcdeals.com
// @version      1
// @description  replaces reddits youtube/vimeo iframe with the iframe from the corresponding website
// @author       kmc
// @match        https://*.reddit.com/*
// @require      https://w.soundcloud.com/player/api.js
// ==/UserScript==

$(document).on('click', ".expando-button.video.expanded", function(event) {
	var href = $(event.target).parent().find("a.title").attr("href");
    var iFrame = $(event.target).parent().find(".expando").children()[0];
    
    if(href.indexOf("vimeo") > -1) {
		href = href.replace(/https?:\/\/vimeo\.com/, "//player.vimeo.com/video");
        replaceiFrame(iFrame, href, "vimeo-iframe");
    }
    
    if(href.indexOf("youtube") > -1 || href.indexOf("youtu.be") > -1) {        
        var videoIDExp = new RegExp(/(v=|be\/)(.{11})/g);
        var videoID = videoIDExp.exec(href);
        
        var seconds = extractTimestamp(href)
        
        console.log(videoID)
        
        if (videoID) {
            href = "https://www.youtube.com/embed/" + videoID[2] + "?start=" + seconds;
            
            replaceiFrame(iFrame, href, "youtube-iframe");
        }
    }
    
    if(href.indexOf("soundcloud") > -1) {
        href = "https://w.soundcloud.com/player/?url=" + encodeURIComponent(href)
        replaceiFrame(iFrame, href, "sc-iframe");
        
        var newiFrame = $(event.target).parent().find(".expando").children()[0];
        addVolumeSlider(newiFrame)
    }
});

function replaceiFrame(iFrame, href, _class){
    $(iFrame).replaceWith('<iframe class="' + _class + '" width="610" height="460" src="' + href + '" frameborder="0" allowfullscreen></iframe>');
}

function addVolumeSlider(element){
    var slider = document.createElement('input');
    slider.setAttribute('value', 100);
    slider.setAttribute('type', "range");
    slider.setAttribute('class', "sc-volume-control");
    slider.oninput = changeVolume
    
    var div = document.createElement('div');
    div.textContent = "100";
    
    element.parentElement.appendChild(slider)
    element.parentElement.appendChild(div)
    
    element.outerHTML += "<br>"
}

function changeVolume(event) {
    var widget = event.target.previousSibling.previousSibling.previousSibling
    var volume = event.target.value
    
    event.target.nextSibling.innerHTML = volume
    SC.Widget(widget).setVolume(volume / 100);
    
}

function extractTimestamp(ytLink) {
    var timestamp = ytLink.match(/t=(.*?)(\&|\?|$)/g)
    var seconds = 0;
    
    if (timestamp) {
        var matches = timestamp[0].match(/([0-9]+)[hms]/g);
        var origTimestamp = timestamp[0].split("t=")[1].split("&")[0];
        console.log(timestamp[0])
        if (matches) {
            for (i = 0; i < matches.length; i++){
                if (matches[i].indexOf("h") > -1) { seconds += parseInt(matches[i]) * 60 * 60; }
                if (matches[i].indexOf("m") > -1) { seconds += parseInt(matches[i]) * 60; }
                if (matches[i].indexOf("s") > -1) { seconds += parseInt(matches[i]); }
            }
        } else if (!isNaN(origTimestamp)) {
            seconds = origTimestamp
        }
    }
    console.log(seconds)
    return seconds;
}