Big Timestamp

Adds a timestamp on top of video sites like Amazon Video, YouTube, and more.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          	Big Timestamp
// @description     Adds a timestamp on top of video sites like Amazon Video, YouTube, and more.
//
// @author			Transiscodev
// @namespace       http://github.com/transiscodev
// @copyright       Copyright (C) 2022
//
// @include         http://*.example.com/*
// @include         https://www.amazon.com/gp/video/*
// @include         https://www.youtube.com/watch*
// @include         https://play.hbomax.com/*
// @include         https://vimeo.com/*
// @license         CC BY-NC 3.0
// @require         https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// @version         1.0
// @run-at			document-end
// ==/UserScript==

/**
 * SCRIPT DESCRIPTION.
 *
 * @see http://wiki.greasespot.net/API_reference
 * @see http://wiki.greasespot.net/Metadata_Block
 */

function init(){
window.notice = document.createElement("div");
notice.innerHTML = "00:00:00";
notice.id = "text-notice";
notice.style = "text-shadow: 0px 0px 10px black, 0px 0px 10px black, 0px 0px 10px black; color: yellow; background-color: transparent; font-family: Tahoma, sans-serif; position: absolute; z-index: 99999; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;";
notice.style.fontSize = Math.floor(screen.width/20) + "px";
if (document.readyState !== "complete") {
	window.addEventListener("load", afterDOMLoaded);
} else {
	afterDOMLoaded();
}
}

function afterDOMLoaded() {
	getService()[3]().arrive(getService()[2], {onlyOnce: true, existing: true}, function(){
		updateEngine();
		document.body.prepend(notice);
		dragElement(notice);
		getService()[0]();
		console.log("running X times")
	});
}
function toggleFullScreen() {
	if (
		!document.fullscreenElement && // alternative standard method
		!document.mozFullScreenElement &&
		!document.webkitFullscreenElement
	) {
		// current working methods
		if (document.documentElement.requestFullscreen) {
			document.documentElement.requestFullscreen();
		} else if (document.documentElement.mozRequestFullScreen) {
			document.documentElement.mozRequestFullScreen();
		} else if (document.documentElement.webkitRequestFullscreen) {
			document.documentElement.webkitRequestFullscreen(
				Element.ALLOW_KEYBOARD_INPUT
			);
		}
	} else {
		if (document.cancelFullScreen) {
			document.cancelFullScreen();
		} else if (document.mozCancelFullScreen) {
			document.mozCancelFullScreen();
		} else if (document.webkitCancelFullScreen) {
			document.webkitCancelFullScreen();
		}
	}
}
function dragElement(elmnt) {
	var pos1 = 0,
		pos2 = 0,
		pos3 = 0,
		pos4 = 0;
	if (document.getElementById(elmnt.id + "header")) {
		// if present, the header is where you move the DIV from:
		document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
	} else {
		// otherwise, move the DIV from anywhere inside the DIV:
		elmnt.onmousedown = dragMouseDown;
	}

	function dragMouseDown(e) {
		e = e || window.event;
		e.preventDefault();
		// get the mouse cursor position at startup:
		pos3 = e.clientX;
		pos4 = e.clientY;
		document.onmouseup = closeDragElement;
		// call a function whenever the cursor moves:
		document.onmousemove = elementDrag;
	}

	function elementDrag(e) {
		e = e || window.event;
		e.preventDefault();
		// calculate the new cursor position:
		pos1 = pos3 - e.clientX;
		pos2 = pos4 - e.clientY;
		pos3 = e.clientX;
		pos4 = e.clientY;
		// set the element's new position:
		elmnt.style.top = elmnt.offsetTop - pos2 + "px";
		elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
	}

	function closeDragElement() {
		// stop moving when mouse button is released:
		document.onmouseup = null;
		document.onmousemove = null;
	}
}
function updateEngine() {
	const target = getService()[1]()
	target.addEventListener("timeupdate", function () {
		var hours = ('0' + parseInt(target.currentTime / (60 * 60), 10)).slice(-2);
		var minutes = ('0' + parseInt(target.currentTime / 60, 10)).slice(-2);
		var seconds = ('0' + Math.floor(target.currentTime % 60)).slice(-2);
		notice.innerHTML = `${hours}:${minutes}:${seconds}`;
	});
}
function recreateNode(el, withChildren) {
	if (withChildren) {
	  el.parentNode.replaceChild(el.cloneNode(true), el);
	}
	else {
	  var newEl = el.cloneNode(false);
	  while (el.hasChildNodes()) newEl.appendChild(el.firstChild);
	  el.parentNode.replaceChild(newEl, el);
	}
  }

function getService(){
	if (window.location.toString().includes("amazon.com/gp/video/") ){
		var videoElementString = "#dv-web-player > div > div:nth-child(1) > div > div > div.scalingVideoContainer > div.scalingVideoContainerBottom > div > video:nth-child(1)"
		return [
			function(){
				document.body.arrive(".atvwebplayersdk-fullscreen-button", {onceOnly: true, existing: true}, function(){
						recreateNode(document.getElementsByClassName("atvwebplayersdk-fullscreen-button")[0], true)
						var tracker = document.getElementsByClassName("atvwebplayersdk-fullscreen-button")[0]
						tracker.addEventListener("click", function(){toggleFullScreen()})
					});
			},
			function(){return document.querySelector(videoElementString)},
			videoElementString,
			function(){ return document.body}];
	}
	else if (window.location.toString().includes("youtube.com/watch") ){
		return [
			function(){},
			function(){return document.getElementsByClassName("video-stream html5-main-video")[0]},
			".video-stream,.html5-main-video",
			function(){ return document.body}];
	}
	else if (window.location.toString().includes("play.hbomax.com") ){
		return [
			function(){},
			function(){return document.querySelector("#rn-video > video")},
			"#rn-video > video",
			function(){ return document.body}];
	}
	else if (window.location.toString().includes("vimeo.com") ){
		return [
			function(){},
			function(){return document.querySelector("div.vp-video > div > video")},
			"div.vp-video > div > video",
			function(){ return document.body}];
	}
}


init()