Timvision Enhanced

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 });

})();