4chan webm extension

Adds ability to pause, fullscreen, and close a webm by clicking on it

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

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

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         4chan webm extension
// @namespace    http://tampermonkey.net/
// @version      0.11
// @description  Adds ability to pause, fullscreen, and close a webm by clicking on it
// @author       lolmao
// @match        https://boards.4chan.org/*/thread/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var observer = new MutationObserver(function (mutations, me) {
        for (var i = 0; i < mutations.length; i++) {
            for (var j = 0; j < mutations[i].addedNodes.length; j++) {
                var curr = mutations[i].addedNodes[j];
                if (curr.tagName === "VIDEO") {
                    addListeners(curr);
                }
            }
        }
    });
    observer.observe(document, {
        childList: true,
        subtree: true
    });
})();


function addListeners(videoObj){
    videoObj.addEventListener('click', function(ev) {
        //ev.preventDefault();
        if (videoObj.paused) {
            videoObj.play();
        } else {
            videoObj.pause();
        }
        return true;
    }, false);

    videoObj.addEventListener('dblclick', function(){
        if (!videoObj.webkitDisplayingFullscreen){
            videoObj.webkitRequestFullscreen();
        } else {
            videoObj.webkitExitFullscreen();
        }
    }, false);

    videoObj.addEventListener('contextmenu', function(ev) {
        ev.preventDefault();
        videoObj.parentElement.firstElementChild.children[1].firstElementChild.click();
    });
    return true;
}