Skip to content

Instantly share code, notes, and snippets.

@donnaken15 donnaken15/YText.user.js
Last active Sep 10, 2019

Embed
What would you like to do?
YourTube %YText+ *1> | YouTube Userscript Extension
// ==UserScript==
// @name YourTube %YText+
// @namespace http://donnaken15.tk
// @version *1>
// @description Extender and extras
// @author donnaken15
// @match *://*.youtube.com/*
// @grant none
// @run-at document-end
// @downloadURL https://gist.github.com/donnaken15/3d160cc0055fb3cbc9ca489ef9a476a6
// @updateURL https://gist.github.com/donnaken15/3d160cc0055fb3cbc9ca489ef9a476a6
// ==/UserScript==
document.getElementById("footer").innerHTML += "YText by <a href='https://www.youtube.com/donnaken15'>donnaken15</a>";
window.addEventListener("transitionend",function(e){
if (window.location.href.includes("youtube.com/playlist")) {
setTimeout((function() {
var originaldetails = document.getElementsByClassName("pl-header-details")[0].innerHTML;
function refreshlength() {
var playlisttime, hour = 0, minute = 0, second = 0, colons = 1;
document.getElementsByClassName("pl-header-details")[0].innerHTML = originaldetails;
for (var i = 0; i < document.getElementsByClassName("timestamp").length; i++)
{
playlisttime = document.getElementsByClassName("timestamp")[i].innerText;
switch ((playlisttime.match(/:/g) || []).length)
{
case 1:
minute += parseInt(playlisttime.substring(0,playlisttime.indexOf(":")));
second += parseInt(playlisttime.substring(playlisttime.indexOf(":")+1));
break;
case 2:
hour += parseInt(playlisttime.substring(0,playlisttime.indexOf(":")));
minute += parseInt(playlisttime.substring(playlisttime.indexOf(":")+1));
second += parseInt(playlisttime.substring(playlisttime.indexOf(":")+4));
break;
}
}
while (second > 60)
{
second -= 60;
minute++;
}
if (minute > 60) {
colons = 2;
}
while (minute > 60)
{
minute -= 60;
hour++;
}
switch (colons)
{
case 1:
playlisttime = (minute).toString()+":0".substring(0,1+(second<10))+(second).toString();
break;
case 2:
playlisttime = (hour).toString()+":0".substring(0,1+(minute<10))+(minute).toString()+":0".substring(0,1+(second<10))+(second).toString();
break;
}
document.getElementsByClassName("pl-header-details")[0].innerHTML = originaldetails + "<li>Length: "+playlisttime+"</li><button class='yt-badge yt-uix-button yt-uix-button-size-small yt-uix-button-default yt-uix-button-has-icon inq-no-click' type='button' onclick='refreshlength()' id='pl-headers-details-length-refresh'>↻</button>";
}
if (e.target.className === "ytp-large-play-button ytp-button") {
var script = document.createElement('script');
script.appendChild(document.createTextNode('var originaldetails = document.getElementsByClassName("pl-header-details")[0].innerHTML;'));
script.appendChild(document.createTextNode(refreshlength));
script.appendChild(document.createTextNode('document.getElementsByClassName(\'playlist-actions\')[0].innerHTML += \'<a href="\'+document.getElementById(\'pl-video-table\').childNodes[1].childNodes[(Math.floor((Math.random()*(parseInt(document.getElementsByClassName(\'pl-header-details\')[0].childNodes[1].textContent.replace(" videos",""))))/2)*2)+1].childNodes[4].childNodes[1].attributes[2].value+"&shuffle="+(Math.floor(Math.random()*100000000))+\'" class="yt-uix-button yt-uix-button-playlist-action yt-uix-sessionlink yt-uix-button-default no-icon-markup "><span class="yt-uix-button-icon yt-sprite" style="background: no-repeat url(//s.ytimg.com/yts/imgbin/www-hitchhiker-vflKml5Tv.png) -101px -252px;width: 14px;height: 12px;"></span><span class="yt-uix-button-content"> Shuffle</span></a>\';'));
(document.body || document.head || document.documentElement).appendChild(script);}}),25);
setTimeout((function() {refreshlength();}),25);}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.