Created
September 25, 2023 10:23
-
-
Save 123DMWM/e318998068621d9737b508e662d15e13 to your computer and use it in GitHub Desktop.
My custom userscript for changing the tab name while watching a youtube video.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Timestamp Tab Name | |
// @version 0.1 | |
// @description Changed the tab name to contain the playing status and duration | |
// @match https://www.youtube.com/watch* | |
// @author 123DMWM | |
// @grant none | |
// @run-at document-idle | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var ytplayer = document.getElementById("movie_player"); | |
const intervaltitle = setInterval(function() { | |
var newTitle = getPlayPause(ytplayer) + " [" + getTimeStamp(ytplayer.getCurrentTime()) + "/" + getTimeStamp(ytplayer.getDuration()) + "] " + $("a.ytp-title-fullerscreen-link").text(); | |
if (!(document.title === newTitle)){ | |
document.title = newTitle; | |
} | |
}, 250); | |
function getTimeStamp(SECONDS){ | |
return new Date((SECONDS * 1000) / ytplayer.getPlaybackRate()).toISOString().substr(11, 8).replace(/^[0:]{0,4}/,''); | |
} | |
function getPlayPause(ytplayer){ | |
if (ytplayer.getPlayerState() ==0){ | |
return "■"; | |
} else if (ytplayer.getPlayerState() == 1) { | |
return "▶"; | |
} else if (ytplayer.getPlayerState() == -1) { | |
return ""; | |
} else { | |
return "❚❚"; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment