Greasy Fork is available in English.

Youtube exakter Hochladezeitpunkt (Veraltet: Siehe Beschreibung für den Link zum neuen Skript)

Fügt die Uhrzeit zum Hochladezeitpunkt hinzu.

Skript installieren?
Vom Ersteller vorgeschlagenes Skript

Ihnen könnte auch YouTube exakter Hochladezeitpunkt gefallen.

Skript installieren
// ==UserScript==
// @name         Youtube exakter Hochladezeitpunkt (Veraltet: Siehe Beschreibung für den Link zum neuen Skript)
// @description  Fügt die Uhrzeit zum Hochladezeitpunkt hinzu.
// @require      https://cdn.jsdelivr.net/npm/hacktimer@1.1.3/HackTimer.min.js
// @require      http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js
// @match        https://www.youtube.com/*
// @version      0.3
// @grant        none
// @namespace    https://greasyfork.org/users/94906
// ==/UserScript==

// HackTimer wird genutzt um setInterval in Tabs zu nutzen, die im Hintergrund sind. Ohne diese Einbindung ist der Counter möglicherweise falsch
// moment wird für das Formatieren und Vergleichen von Datum und Uhrzeit genutzt

(function() {
  'use strict';
  var YT_API_KEY = "Mein API-Key";
  console.log("YT EXACT UPLOAD LOADED");
  var BASE_URL = "https://www.googleapis.com/youtube/v3/videos?part=snippet,liveStreamingDetails,contentDetails,localizations,player,statistics,status&key=" + YT_API_KEY;
  var interval = null;
  var changeCheckTimer = null;
  var currentVideoId = null;
  function genUrl(){
    const urlParams = new URLSearchParams(window.location.search);

    if(urlParams.get("v") != null){
      return BASE_URL + "&id=" + urlParams.get("v");
    }else {
      return "";
    }
  }
  function isUndefinedOrNull(obj) {
    return obj == undefined || obj == null;
  }
  function sleep(milliseconds) {
    return new Promise(resolve => setTimeout(resolve, milliseconds));
  }
  function formatMilliseconds(milliseconds, joinString, showDays, showHours, showMinutes, showSeconds, showMilliseconds, pad, hideDaysOnNull) {
    let result = '';
    let days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
    let hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24);
    let minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
    let seconds = Math.floor((milliseconds / 1000) % 60);
    milliseconds = milliseconds % 1000;
    if (showDays) {
      if (days < 1 && hideDaysOnNull) {
      } else {
        if (result != '')
          result += joinString;
        if (pad) {
          if (days < 10)
            result += '0' + days;
          else
            result += days;
        } else
          result += days;
      }
    }
    if (showHours) {
      if (result != '')
      	result += joinString;
      if (pad)
      	result += ('0' + hours).slice(-2);
      else
        result += hours;
    }
    if (showMinutes) {
      if (result != '')
      	result += joinString;
      if (pad)
      	result += ('0' + minutes).slice(-2);
      else
        result += minutes;
    }
    if (showSeconds) {
      if (result != '')
      	result += joinString;
      if (pad)
      	result += ('0' + seconds).slice(-2);
      else
        result += seconds;
    }
    if (showMilliseconds) {
      if (result != '')
      	result += joinString;
      if (pad)
      	result += ('00' + milliseconds).slice(-3);
      else
        result += milliseconds;
    }
    return result;
  }
  function updateOngoing(durationInMilliseconds) {
    if (!isUndefinedOrNull(interval)) {
      clearInterval(interval);
      interval = null;
    }
    let duration = durationInMilliseconds;
    interval = setInterval(function() {
      duration += 500;
      document.getElementById("ongoing-video-duration").innerHTML = formatMilliseconds(duration, ':', true, true, true, true, false, true, true);
    }, 500);
  }
 	async function updateLiveContent(premiere, livestream, data, mom) {
    var element = null;
    while (isUndefinedOrNull(element)) {
      element = document.getElementById("date");
      await sleep(200);
    }
    var durationInMilliseconds = null;
    var ongoing = false;
    var innerHTML = "<span id=\"dot\" class=\"style-scope ytd-video-primary-info-renderer\">•</span>";
    if (!premiere && !livestream) { // Normales Video
      if (mom.isSame(moment(), 'day')) // Heute
        innerHTML += mom.format('HH:mm:ss') + " Uhr";
      else
        innerHTML += mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
    } else {
      if (isUndefinedOrNull(data.items[0].liveStreamingDetails.actualStartTime)) { // Geplant
        mom = moment(data.items[0].liveStreamingDetails.scheduledStartTime);
        if (mom.isSame(moment(), 'day')) { // Heute
          if (livestream)
          	innerHTML += "Livestream geplant für: " + mom.format('HH:mm:ss') + " Uhr";
          else if (premiere)
            innerHTML += "Premiere geplant für: " + mom.format('HH:mm:ss') + " Uhr";
          else
            innerHTML += mom.format('HH:mm:ss') + " Uhr";
        } else {
          if (livestream)
          	innerHTML += "Livestream geplant für: " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
          else if (premiere)
            innerHTML += "Premiere geplant für: " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
          else
            innerHTML += mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
        }
      } else { // Laufend / Beendet
        mom = moment(data.items[0].liveStreamingDetails.actualStartTime);
        var endTime = null;
        if (!isUndefinedOrNull(data.items[0].liveStreamingDetails.actualEndTime))
          endTime = moment(data.items[0].liveStreamingDetails.actualEndTime);
        if (endTime == null) { // Laufend
          ongoing = true;
          durationInMilliseconds = moment.duration(moment().diff(mom)).asMilliseconds();
          if (mom.isSame(moment(), 'day')) { // Heute
            if (livestream)
            	innerHTML += "Aktiver Livestream seit " + mom.format('HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
            else if (premiere)
            	innerHTML += "Aktive Premiere seit " + mom.format('HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
            else
              innerHTML += "Seit " + mom.format('HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
          } else {
            if (livestream)
            	innerHTML += "Aktiver Livestream seit " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
            else if (premiere)
              innerHTML += "Aktive Premiere seit " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
            else
              innerHTML += "Seit " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr (<span id=\"ongoing-video-duration\">" + formatMilliseconds(durationInMilliseconds, ':', true, true, true, true, false, true, true) + "</span>)";
          }
        } else { // Beendet
          if (mom.isSame(moment(), 'day')) { // Heute
            if (livestream)
            	innerHTML += "Livestream von " + mom.format('HH:mm:ss') + " Uhr";
            else if (premiere)
              innerHTML += "Premiere von " + mom.format('HH:mm:ss') + " Uhr";
            else
              innerHTML += mom.format('HH:mm:ss') + " Uhr";
          } else {
            if (livestream)
            	innerHTML += "Livestream vom " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
            else if (premiere)
            	innerHTML += "Premiere vom " + mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
            else
              innerHTML += mom.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
          }
          if (mom.isSame(endTime, 'day')) // Heute
            innerHTML = innerHTML.replace('um', 'von') + " bis " + endTime.format('HH:mm:ss') + " Uhr";
          else
            innerHTML = innerHTML.replace('um', 'von') + " bis zum " + endTime.format('DD.MM.YYYY [um] HH:mm:ss') + " Uhr";
        }
      }
    }
    var contentRating = data.items[0].contentDetails.contentRating;
    if (!isUndefinedOrNull(contentRating.ytRating) && contentRating.ytRating == 'ytAgeRestricted')
      innerHTML += " - FSK 18";
    element.innerHTML = innerHTML;
    if (ongoing)
      updateOngoing(durationInMilliseconds);
    return ongoing;
  }
  function updateLiveContentWithChangeCheck(premiere, livestream, data, mom) {
    var ongoing = updateLiveContent(premiere, livestream, data, mom);
    /*document.getElementsByClassName('html5-main-video')[0].addEventListener('ended', function() {
      fetch('https://www.youtube.com/get_video_info?video_id=' + currentVideoId).then(function(response) {
        return response.text();
      }).then(function(video_info) {
        try {
          let player_response = decodeURIComponent(video_info);
          let urlParams = new URLSearchParams(player_response);
          if (urlParams.get("player_response") != null) {
            player_response = urlParams.get("player_response");
          }
          player_response = JSON.parse(player_response);
          var premiere = !isUndefinedOrNull(player_response) && !player_response.videoDetails.isLiveContent;
          premiere = premiere && !isUndefinedOrNull(data.items[0].liveStreamingDetails);
          var livestream = !isUndefinedOrNull(player_response) && player_response.videoDetails.isLiveContent;
          var live = !isUndefinedOrNull(player_response) && player_response.videoDetails.isLive;
          if (ongoing)
          	updateLiveContent(premiere, livestream, data, mom);
        } catch (ex) {
          console.error(ex);
        }
      }).catch(error => console.error("YOUTUBE EXACT UPLOAD ERROR: " + error, "\nget_video_info doesn't seem to work"));
    });*/
  }
  function getExactUploadDate() {
    var abort = false;
    const processEvent = async () => {
      await sleep(500);
    	const urlParams = new URLSearchParams(window.location.search);
      if (urlParams.get("v") != null){
        let videoId = urlParams.get("v");
        if (videoId == currentVideoId) {
        	abort = true;
        } else {
        	currentVideoId = videoId;
        }
      }
      if ((YT_API_KEY != "" || typeof YT_API_KEY != "undefined") && !abort) {
        var url = genUrl();
        if (url != "") {
          fetch(url).then(function(response) {
            return response.json();
          }).then(function(data) {
            if (data.pageInfo.totalResults > 0) {
              const addTime = async () => {
                
                var mom = moment(data.items[0].snippet.publishedAt);
                console.log(mom);
                
                /*var movie_player = undefined;
                if (window.movie_player)
                  movie_player = window.movie_player;
                else
                  movie_player = document.getElementById("movie_player");
                console.log(movie_player);
                try {
  								console.log(movie_player.getPlayerResponse());
                } catch (ex) {
                  console.error(ex);
                }*/
                fetch('https://www.youtube.com/get_video_info?video_id=' + currentVideoId).then(function(response) {
                  return response.text();
                }).then(function(video_info) {
                  if (!isUndefinedOrNull(interval)) {
                    clearInterval(interval);
                    interval = null;
                  }
                  if (!isUndefinedOrNull(changeCheckTimer)) {
                    clearInterval(changeCheckTimer);
                    changeCheckTimer = null;
                  }
                  try {
                    let player_response = decodeURIComponent(video_info);
                    let urlParams = new URLSearchParams(player_response);
                    if (urlParams.get("player_response") != null) {
                      player_response = urlParams.get("player_response");
                    }
                    player_response = JSON.parse(player_response);// data.items[0].status.privacyStatus = "public" -> Öffentliches Video
                    var premiere = !isUndefinedOrNull(player_response) && !player_response.videoDetails.isLiveContent;
                    premiere = premiere && !isUndefinedOrNull(data.items[0].liveStreamingDetails);
                    var livestream = !isUndefinedOrNull(player_response) && player_response.videoDetails.isLiveContent;
                    var innerHTML = "<span id=\"dot\" class=\"style-scope ytd-video-primary-info-renderer\">•</span>";
                    updateLiveContentWithChangeCheck(premiere, livestream, data, mom);
                  } catch (ex) {
                    console.error(ex);
                  }
                }).catch(error => console.error("YOUTUBE EXACT UPLOAD ERROR: " + error, "\nget_video_info doesn't seem to work"));
              }
              addTime();
            }
          }).catch(error => console.error("YOUTUBE EXACT UPLOAD ERROR: " + error, "\nINVALID API KEY?"));
        }
      } else {
        if(!abort)
        	console.error("YOUTUBE EXACT UPLOAD ERROR: Undefined api key");
      }
    }
    processEvent();
  }
  //getExactUploadDate();
  //document.addEventListener('click', getExactUploadDate);
  //document.addEventListener('yt-page-data-updated', getExactUploadDate);
  document.addEventListener('yt-navigate-finish', getExactUploadDate);
})();