// ==UserScript== // @name 9gag auto video control // @namespace http://tampermonkey.net/ // @version 0.1 // @description Automatically add video controls to videos on 9gag, without using timeout (which use a lot of ressource), but using MutationObserver instead (kind of an event when a video is added). The controls are added when you click on the video, to prevent problems with the function that put sound when you click. // @author You // @match https://9gag.com/ // @icon https://www.google.com/s2/favicons?domain=9gag.com // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let addVideo = (dom) => dom.querySelectorAll('video').forEach(video => video.addEventListener('click', () => { video.setAttribute('controls', true) })); addVideo(document.getElementById('list-view-2')); (new MutationObserver(function (mutationlist) { mutationlist.forEach(mutation => { if (mutation.addedNodes) { mutation.addedNodes.forEach(addedNode => { if (addedNode.classList.contains('list-stream')) { addVideo(addedNode); } }); } }); })).observe(document.getElementById('list-view-2'),{ attributes: false, childList: true, subtree: false}); })();