Youtube Player Speed Slider

Add Speed Slider to Youtube Player Settings

当前为 2016-11-22 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube Player Speed Slider
// @namespace    youtube_player_speed_slider
// @version      0.1.0
// @description  Add Speed Slider to Youtube Player Settings
// @author       Łukasz
// @match        https://*.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var YT_F = {};

    YT_F.option = {
        menu:null,
        speedMenu: null,
        label:null,
        menuClass : "ytp-menuitem",
    };

    YT_F.new = function(tag, option){
        var element = document.createElement(tag);
        for(var param in option){
            element[param] = option[param];
        }
        return element;
    };

    YT_F.get = function(tselector, all){
        all = all || false;
        var type = tselector.substring(0,1);
        var selector = tselector.substring(1);
        if(type == "#"){
            return document.getElementById(selector);
        }
        else if(type == "."){
            var elements = document.getElementsByClassName(selector);
            if(all){
                return elements;
            }
            else{
                return elements.length ? elements[0] : null;
            }
        }
    };

    YT_F.build = function() {
        YT_F.option.menu = YT_F.get('.ytp-panel-menu');
        YT_F.option.menu.appendChild(YT_F.buildSpeedMenu());
    };

    YT_F.buildSpeedMenu = function(){
        YT_F.option.speedMenu = YT_F.new('div', {'className':'ytp-menuitem'});

	    YT_F.option.speedMenu.label = YT_F.new('div', {'className':'ytp-menuitem-label', 'innerHTML':'<b>Szybkość: 1</b>'});
	    var right = YT_F.new('div', {'className':'ytp-menuitem-content'});
	    var range = YT_F.new('input', {'className':'', 'type':'range', 'min':0.5, 'max':4, 'step':0.1, 'value':1});
        document.addEventListener('change', YT_F.onchange);

        right.appendChild(range);
        YT_F.option.speedMenu.appendChild(YT_F.option.speedMenu.label);
        YT_F.option.speedMenu.appendChild(right);
        return YT_F.option.speedMenu;
    };

    YT_F.updateLabel = function(value){
        YT_F.option.speedMenu.label.innerHTML = "Szybkość: " + value;
    };

    YT_F.onchange = function(event){
        YT_F.updateLabel(event.target.value);
        YT_F.updatePlayerSpeed(event.target.value);
    };

    YT_F.updatePlayerSpeed= function(value){
        YT_F.get('.html5-main-video').playbackRate = value;
    };

    YT_F.annotationsSwitchOffAndRemoveDefaultSpeedMenu = function(){
        var settings_button = YT_F.get(".ytp-settings-button");
        settings_button.click(); settings_button.click();

        var all_labels = document.getElementsByClassName("ytp-menuitem-label");
        for (var i = 0; i < all_labels.length; i++) {
            if ((all_labels[i].innerHTML == "Annotations" || all_labels[i].innerHTML == "Adnotacje") &&
                (all_labels[i].parentNode.getAttribute("aria-checked") == "true")) {
                all_labels[i].parentNode.click();
            }
            if (all_labels[i].innerHTML == "Speed" || all_labels[i].innerHTML == "Szybkość"){
                all_labels[i].parentNode.style.display = 'none';
            }
        }
    };

    YT_F.build();
    YT_F.annotationsSwitchOffAndRemoveDefaultSpeedMenu();

})();