Skip to content

Instantly share code, notes, and snippets.

@mwicat
Last active June 9, 2020 16:38
Show Gist options
  • Select an option

  • Save mwicat/ab27b84c12b3d5d3532562ab06f3b7f9 to your computer and use it in GitHub Desktop.

Select an option

Save mwicat/ab27b84c12b3d5d3532562ab06f3b7f9 to your computer and use it in GitHub Desktop.
tampermonkey_youtube_timestamp.js
// ==UserScript==
// @name YouTube add timestamped link
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically update link with timestamp that you may later use for bookmarking
// @author mwicat
// @match *://www.youtube.com/watch*
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(function () {
var ytplayer = document.getElementById("movie_player");
var link = document.createElement('a');
var updateLink = function() {
var tmTotalSeconds = Math.round(ytplayer.getCurrentTime());
var tmMinutes = Math.floor(tmTotalSeconds / 60);
var tmSeconds = tmTotalSeconds - tmMinutes * 60;
var tmString = ' - ' + tmMinutes.toString() + 'm' + tmSeconds.toString().padStart(2, '0') + 's';
link.text = ytplayer.getVideoData().title + tmString;
var url = ytplayer.getVideoUrl() + '&t=' + tmTotalSeconds;
link.href = url;
};
var contents = document.getElementById('start');
contents.append(link);
setInterval(updateLink, 1000);
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment