Safari Embedded WebM Support

Uses the VLC webplugin to play embeded webM videos.

ของเมื่อวันที่ 09-09-2018 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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