Youtube End Timer

A script that lets you know the time when a youtube video will end.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Youtube End Timer
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  A script that lets you know the time when a youtube video will end.
// @author       You
// @match        *://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

function getDateFromHours(time) {
    if(time.length < 6)
        time = "00:" + time;
    time = time.split(':');
    let now = new Date();
    return new Date(now.getFullYear(), now.getMonth(), now.getDate(), ...time);
}


function dateToString(time) {
    let datetext = time.toTimeString().split(' ')[0];
    let dateArr = datetext.split(':');

    return dateArr[0] + ":" + dateArr[1];
}

function getSpeed(){
        return video.playbackRate;
}

function setEndTime(){
    let diff = (video.duration - video.currentTime) * 1000;
    let endDate = new Date(Date.now() + Math.round(diff/getSpeed()) );
    span.textContent = "Ends at " + dateToString(endDate);
}

function startUp(){
    span = document.getElementById("ytp-time-end");
    if(!span){
        span = document.createElement("span");
        span.setAttribute("id", "ytp-time-end");
        span.setAttribute("style", "padding-left:10px; color:#ddd;");
        document.getElementsByClassName("ytp-time-duration")[0].insertAdjacentElement("afterend", span);
    }

     video = document.getElementsByClassName("html5-video-container")[0]
    .getElementsByClassName("video-stream html5-main-video")[0];
    video.addEventListener('timeupdate', setEndTime);
    video.addEventListener('ratechange', setEndTime);
    setEndTime();
}

document.body.addEventListener("yt-navigate-finish", function(event) {
    startUp();
});

let span;
let video;
let interval = setInterval(function(){setEndTime();}, 30000);


})();