Skip to content

Instantly share code, notes, and snippets.

@boostup
Last active June 5, 2018 23:05
Show Gist options
  • Save boostup/aa1c92128bf674eceadeede8f6cc91b4 to your computer and use it in GitHub Desktop.
Save boostup/aa1c92128bf674eceadeede8f6cc91b4 to your computer and use it in GitHub Desktop.
This code is some quick and dirty one! This is not meant for production code. It is meant to run as bookmarklet on chrome latest. On the browser, the page opened must be a playing video at https://www.youtube.com. Then, clicking on the bookmarklet containing this code will allow to log into the browser console the video metadata, time elapsed al…
function minTohhmmss(totalSeconds){
var hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
var minutes = Math.floor(totalSeconds / 60);
var seconds = Math.floor(totalSeconds % 60);
var ret = "";
hours ? ret = hours + "h" : "";
minutes ? ret += minutes + "m": "";
seconds ? ret += seconds + "s": "";
return ret;
}
function highlight(text) {
var styles = [
'background: linear-gradient(#D33106, #571402)'
, 'border: 1px solid #3E0E02'
, 'color: white'
, 'display: block'
, 'text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3)'
, 'box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 5px 3px -5px rgba(0, 0, 0, 0.5), 0 -13px 5px -10px rgba(255, 255, 255, 0.4) inset'
, 'line-height: 40px'
, 'text-align: center'
, 'font-weight: bold'
].join(';');
console.log('%c'+text, styles);
}
var ytplayer = document.getElementById("movie_player");
var elapsed = minTohhmmss(ytplayer.getCurrentTime());
var videoUrl = ytplayer.getVideoUrl();
var videoTitle = document.querySelector("ytd-video-primary-info-renderer h1").innerText;
var comment = prompt("Please enter a comment for this video @" + elapsed, "test");
if (comment != null) {
highlight(videoTitle + " @ " + elapsed + "\n" + videoUrl + "&t=" + elapsed + "\n" + comment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment