Safari Embedded WebM Support

Uses the VLC webplugin to play embeded webM videos.

Από την 09/09/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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