Timvision Enhanced

Aggiunge scorciatoie simili a quelle di Youtube a timvisiontv.tim.it

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           Timvision Enhanced
// @name:it        Timvision Enhanced
// @namespace      http://cosoleto.free.fr/
// @version        0.5
// @description    Aggiunge scorciatoie simili a quelle di Youtube a timvisiontv.tim.it
// @description:it Aggiunge scorciatoie simili a quelle di Youtube a timvisiontv.tim.it
// @author         Francesco Cosoleto
// @match          http*://timvisiontv.tim.it/*
// @exclude        http*://timvisiontv.tim.it/profile*
// @exclude        http*://timvisiontv.tim.it/promo*
// @exclude        http*://timvisiontv.tim.it/support*
// @grant          none
// ==/UserScript==

(function() {
    'use strict';

    var statusbar = document.createElement('div');
    statusbar.setAttribute('style', [
        'position: fixed',
        'bottom: 80px',
        'left: 50%',
        'transform: translateX(-50%)',
        'background: rgba(0,0,0,0.75)',
        'color: white',
        'font-size: 16px',
        'font-family: sans-serif',
        'padding: 6px 14px',
        'border-radius: 4px',
        'pointer-events: none',
        'z-index: 2147483647',
        'display: none'
    ].join(';'));
    document.body.appendChild(statusbar);

    var statusTimeout = null;

    function showStatus(text) {
        statusbar.innerText = text;
        statusbar.style.display = 'block';
        if (statusTimeout) clearTimeout(statusTimeout);
        statusTimeout = setTimeout(function() {
            statusbar.style.display = 'none';
        }, 5000);
    }

    function isFullscreen() {
        return document.fullscreen || document.webkitIsFullScreen || document.mozFullScreen || false;
    }

    function toggleFullscreen() {
        if (isFullscreen()) {
            document.exitFullscreen();
        } else {
            var fsbut = document.querySelector('.fullscreen-button, [class*="fullscreen"], [aria-label*="fullscreen" i], [aria-label*="schermo intero" i]');
            if (fsbut) {
                var btn = fsbut.firstElementChild || fsbut;
                btn.click();
            }
        }
    }

    function findVideo() {
        return document.getElementById('videoPlayer')
            || document.querySelector('video[src], video[srcObject]')
            || document.querySelector('video');
    }

    function keydown(e) {
        var tag = document.activeElement.tagName;
        if (tag !== 'BODY' && tag !== 'VIDEO' && tag !== 'DIV') {
            return;
        }

        var vid = findVideo();
        if (!vid) {
            return;
        }

        if (e.ctrlKey || e.altKey) {
            return;
        }

        switch (e.key) {
            case 'f':
            case 'F':
                toggleFullscreen();
                e.preventDefault();
                break;
            case 'k':
            case 'K':
            case ' ':
                if (vid.paused) { vid.play(); } else { vid.pause(); }
                e.preventDefault();
                break;
            case 'm':
            case 'M':
                vid.muted = !vid.muted;
                e.preventDefault();
                break;
            case 'j':
                vid.currentTime -= 10;
                e.preventDefault();
                break;
            case 'l':
                vid.currentTime += 10;
                e.preventDefault();
                break;
            case '0':
                vid.currentTime = 0;
                e.preventDefault();
                break;
            case '1': case '2': case '3': case '4': case '5':
            case '6': case '7': case '8': case '9':
                vid.currentTime = (parseInt(e.key) / 10) * vid.duration;
                e.preventDefault();
                break;
            default:
                switch (e.keyCode) {
                    case 35: // End
                        vid.currentTime = vid.duration;
                        break;
                    case 36: // Home
                        vid.currentTime = 0;
                        break;
                    case 37: // ArrowLeft
                        vid.currentTime -= 5;
                        e.preventDefault();
                        break;
                    case 39: // ArrowRight
                        vid.currentTime += 5;
                        e.preventDefault();
                        break;
                    case 38: // ArrowUp
                        vid.volume = Math.min(1, vid.volume + 0.1);
                        showStatus('Volume: ' + Math.round(vid.volume * 100) + '%');
                        e.preventDefault();
                        break;
                    case 40: // ArrowDown
                        vid.volume = Math.max(0, vid.volume - 0.1);
                        showStatus('Volume: ' + Math.round(vid.volume * 100) + '%');
                        e.preventDefault();
                        break;
                    case 188: // ,
                        vid.playbackRate = Math.max(0.1, parseFloat((vid.playbackRate - 0.1).toFixed(1)));
                        showStatus('Velocità: ' + vid.playbackRate.toFixed(1));
                        e.preventDefault();
                        break;
                    case 190: // .
                        vid.playbackRate = parseFloat((vid.playbackRate + 0.1).toFixed(1));
                        showStatus('Velocità: ' + vid.playbackRate.toFixed(1));
                        e.preventDefault();
                        break;
                }
        }
    }

    window.addEventListener('keydown', keydown, false);

    // Gestisce player caricato dinamicamente (SPA)
    var observer = new MutationObserver(function(mutations) {
        for (var m of mutations) {
            for (var node of m.addedNodes) {
                if (node.nodeType === 1) {
                    if (node.tagName === 'VIDEO' || (node.querySelector && node.querySelector('video'))) {
                        return;
                    }
                }
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();