bvdeenen icon

tampermonkey youtube total time

bvdeenen | PRO | 02/18/18 07:28:40 PM UTC | 0 ⭐ | 965 👁️ | Never ⏰ | []
JavaScript |

1.36 KB

|

None

|

0 👍

/

0 👎

// ==UserScript==
// @version     1.0.0
// @name        Show total runtime for YouTube playlist
// @match       https://www.youtube.com/playlist*
// @run-at      document-end
// @grant       none
// @require http://code.jquery.com/jquery-latest.js
// @noframes
// ==/UserScript==
(function youtube_total_time() {
    'use strict';
    function totalTime(a) {
        var x = $("#contents .ytd-thumbnail .ytd-thumbnail-overlay-time-status-renderer");
        x.css({backgroundColor:'yellow', color:'black'});
        x=x.text();
        if(!x) return false;
 
        x=x.trim().split(/\s+/);
        console.log(x);
        var totalTime = 0;
        for (var i = 0; i < x.length; i++) {
            var ms = x[i].split(':');
            totalTime += Number.parseInt(ms[0]) * 60 + Number.parseInt(ms[1]);
        }
        var mins = Math.floor(totalTime / 60);
        var secs = Math.round(totalTime - mins * 60);
        return mins + ":" + secs;
    }
    window.setTimeout(function(){
        var t = totalTime();
 
        console.log(t);
        if(t){
            var x = $("<div>", {text: "Total time: "+t});
            x.appendTo($("body"));
            x.css({position:'fixed', top:0, left:'5em', zIndex:10000, color: 'black', background: 'yellow',
                   margin: 5, padding:5, fontSize: 'large'});
 
        }
    }, 3000);
}());

Comments