Youtube Up Next Time Since Upload

In the up next queue on Youtube, include the time since upload as part of the displayed metadata

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube Up Next Time Since Upload
// @namespace    https://github.com/deelawn/user-scripts
// @version      0.3
// @description  In the up next queue on Youtube, include the time since upload as part of the displayed metadata
// @author       deelawn
// @include      /^http(s?)://((www\.)?)youtube\.com/watch(.*)$/
// @grant        none
// @require      http://code.jquery.com/jquery-latest.js
// ==/UserScript==

// Check every second for upcoming videos with no uploaded time metadata displayed
var myTimer = setInterval(
  function () {
    'use strict';

    $("ytd-watch-next-secondary-results-renderer.ytd-watch > div[id='items']").children().each(function() {
      var nextObj;

      // The video up next is structured a bit differently, so check for that
      if($(" > div[id='head']", this).length){
        nextObj = $(" > ytd-compact-video-renderer", this);
      }else{
        nextObj = this;
      }

      if(!($(" > div[id='dismissable']", nextObj).length)){
        return;
      }

      nextObj = $(" > div[id='dismissable']", nextObj);

      // Don't add the time span if it's already there
      if($(" > a > ytd-video-meta-block > div[id='metadata'] > div[id='metadata-line'] > span[id='time-since-upload']", nextObj).length){
        return;
      }

      var rawLabel = $(" > a > h3 > span", nextObj).attr("aria-label");
      var regEx = /.*?\sby\s.*?\s((\d+)\s((year(s?))|(month(s?))|(week(s?))|(day(s?))|(hour(s?))|(minute(s?))|(second(s?))))\sago/;
      var timeSinceUpload = regEx.exec(rawLabel)[1];
      var timeSpan = "<span id=\"time-since-upload\" class=\"style-scope ytd-video-meta-block\">".concat(timeSinceUpload.concat("</span>"));

      $(" > a > ytd-video-meta-block > div[id='metadata'] > div[id='metadata-line'] > span", nextObj).after(timeSpan);
    });
}, 3000);