9GAG Show Controls

Automatically adds the controls attribute to all video elements.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         9GAG Show Controls
// @namespace    http://www.diamonddownloads.weebly.net
// @version      0.1
// @locale       en-US
// @description  Automatically adds the controls attribute to all video elements.
// @author       RGSoftware, R.F Geraci
// @include      https://9gag.com/*
// @include      http://9gag.com/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant        none
// @icon         http://icons.iconarchive.com/icons/iconleak/stainless/256/script-icon.png
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';

    var scrollDiff = 500; //scrolled pixels


    var Tvideo = {
        oldHeight: $(window).scrollTop(),

        hasScrolled: function(amount){
            var height = $(window).scrollTop();
            //Covers boths scrolling up and scrolling down
            if (Math.abs((height - Tvideo.oldHeight)) >= amount){
                Tvideo.oldHeight = height;
                return true;
            }else{
                return false;
            }
        },
        showControls: function(){
            var v = $('video');

            for (var i=0;i<v.length;i++){
                v[i].setAttribute('controls', 'true');
            }
        },

        isVideos: function(){
            return $('video').length > 0;
        },
    };


    //Check onload for any video, 
    //from then when page scrolled

    if (Tvideo.isVideos){
        Tvideo.showControls();
    }

    $(window).scroll(function(){
        if (Tvideo.hasScrolled(scrollDiff)){

            if (Tvideo.isVideos){
                Tvideo.showControls();
            }

        }

    });


})();