4chan webm extension

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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