Safari Embedded WebM Support

Uses the VLC webplugin to play embeded webM videos.

Stan na 09-09-2018. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Safari Embedded WebM Support
// @namespace    safari-embedded-webm-support
// @version      1.1
// @description  Uses the VLC webplugin to play embeded webM videos.
// @author       Calumks
// @match        *://boards.4chan.org/*
// @match        *://8ch.net/*
// @match        *://gelbooru.com/index.php?page=post&*
// @match        *://danbooru.donmai.us/posts/*
// @grant        none
// @require      http://code.jquery.com/jquery-3.2.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// ==/UserScript==

(function() {

    function embedVLC(video, src) {
        // 4chan
        if (document.URL.indexOf("//boards.4chan") > -1) {
            insert4chan(video, src);
        // Other
        } else {
             // Create video
             var vlc = createVLC(video, src);
             video.before(vlc);

             // Hide video
             video.attr('style', 'width: 0; opacity: 0; height: 0;');
        }
    }

    // Create vlc video to insert
    function createVLC(video, src) {
        // Get source
        var vlc = $('<embed loop="' + video.prop("loop") + '">');
        vlc.attr({
            type: "application/x-vlc-plugin",
            pluginspage: "http://www.videolan.org",
            width: "855",
            height: "481",
            target: src,
        });
        return vlc;
    }

    // 4chan insert
    function insert4chan(video, src) {

        // Add vlc
        var vlc = createVLC(video, src);
        video.parent().before(vlc);
        vlc.attr("style", "margin: 5px 20px");

        // Hide thumb
        var thumb = video.parent().find('img');
        thumb.hide();

        // click to stop loading again
        thumb.click();

        // Create close button
        var closeSpan = $("<span class='collapseWebm'>-[<a>close</a>]</span>");
        var closeLink = $("a", closeSpan) ;
        vlc.prev().append(closeSpan);
        closeLink.click(function() {
            closeSpan.remove();
            vlc.remove();
            thumb.show();
        });
    }

    // Convert html5
    $(document).arrive('video[src$=".webm"]', function() {
        embedVLC($(this), $(this).attr("src"));
    });
    $('video[src$=".webm"]').each(function() {
        embedVLC($(this), $(this).attr("src"));
    });
     $(document).arrive('video source[src$=".webm"]', function() {
        embedVLC($(this).closest('video'), $(this).attr("src"));
    });
    $('video source[src$=".webm"]', $(this).src).each(function() {
        embedVLC($(this).closest('video'), $(this).attr("src"));
    });

})(this);