Button change speed video

Button change speed videos

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Button change speed video
// @namespace    change_speed
// @version      1
// @description  Button change speed videos
// @author       nht
// @include      *
// @grant        unsafeWindow
// @grant        GM_registerMenuCommand
// @run-at       document-start
// ==/UserScript==


GM_registerMenuCommand ("Active Speed", show_ui, "A");

function changeSpeed(self){
    var iframes = unsafeWindow.document.querySelectorAll('iframe');
    var sendData = {id: "my_speed", speed: self.value};
    for(var i = 0; i < iframes.length; i++){
        try{
            iframes[i].contentWindow.postMessage(sendData, "*");
        }catch(e) { console.log(e);}
    }
    changeSpeedIframe(self.value);
}

function changeSpeedIframe(data){

    var speed = parseFloat(data);
    if(isNaN(speed)) {
        return;
    }
    //console.log("find video tag");
    var videos = unsafeWindow.document.querySelectorAll('video');
    //console.log(videos);
    console.log("speed ", speed);
    for(var i = 0; i < videos.length; i++){
        videos[i].playbackRate = speed;
    }
}
unsafeWindow.window.changeSpeed = changeSpeed;
unsafeWindow.window.changeSpeedIframe = changeSpeedIframe;
//event on iframe
if (window.top !== window.self){
    unsafeWindow.window.onmessage = function(event){
        if (event.data && event.data.id === "my_speed"){
            changeSpeedIframe(event.data.speed);
        }
    }
}

function show_ui() {
    var Speeds = ["1.00", "1.25", "1.50", "2.00", "3.00", "500.0"];
    if (window.top === window.self) {
        var div = unsafeWindow.document.createElement("div");
        div.innerHTML = "";
        for(var i = 0; i < Speeds.length; i++){
            div.innerHTML += '<button style="margin-left: 5px; margin-bottom: 5px;" type="button" value="' + Speeds[i] + '" onClick=changeSpeed(this)>x' + Speeds[i] + '</button><br>';
        }
        div.setAttribute("style","z-index:9999; position: -webkit-sticky; position:fixed; bottom: 2px; left:0; font-size: 15px; color: black;");
        //unsafeWindow.document.body.insertBefore(div, unsafeWindow.document.body.firstChild);
        unsafeWindow.document.body.appendChild(div);
    }
}
//unsafeWindow.window.show_ui = show_ui;
//unsafeWindow.document.addEventListener('DOMContentLoaded', show_ui);