MyDealz Embedded Youtube Urls

Adds functionallity to turn plain youtube urls into embedded videos on mydealz.de

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         MyDealz Embedded Youtube Urls
// @namespace    http://www.mydealz.de/profile/richi2k
// @version      0.2
// @description  Adds functionallity to turn plain youtube urls into embedded videos on mydealz.de 
// @author       richi2k
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @match        http://www.mydealz.de/*
// @grant        none
// ==/UserScript==

function isYoutubeUrl(url) 
{
    var p = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
    if(url.match(p)){
        return url.match(p)[1];
    }
    return false;
}
function getYoutubeId(url) {
    var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
    var match = url.match(regExp);

    if (match && match[2]) {
        return match[2];
    } else {
        return 'error';
    }
}

(function() {
    'use strict';
    
    $(".bbcode_url").each(function(){
        if(isYoutubeUrl($(this).attr("href")))
        {
            $(this).replaceWith(function(){
               return '<div><iframe width="400" height="200" src="https://www.youtube.com/embed/' + getYoutubeId( $(this).attr("href") ) + '" frameborder="0" allowfullscreen></iframe></div>'; 
            });
        }
    });
    
})();