Youtube Up Next Time Since Upload

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

  1. // ==UserScript==
  2. // @name Youtube Up Next Time Since Upload
  3. // @namespace https://github.com/deelawn/user-scripts
  4. // @version 0.3
  5. // @description In the up next queue on Youtube, include the time since upload as part of the displayed metadata
  6. // @author deelawn
  7. // @include /^http(s?)://((www\.)?)youtube\.com/watch(.*)$/
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12. // Check every second for upcoming videos with no uploaded time metadata displayed
  13. var myTimer = setInterval(
  14. function () {
  15. 'use strict';
  16.  
  17. $("ytd-watch-next-secondary-results-renderer.ytd-watch > div[id='items']").children().each(function() {
  18. var nextObj;
  19.  
  20. // The video up next is structured a bit differently, so check for that
  21. if($(" > div[id='head']", this).length){
  22. nextObj = $(" > ytd-compact-video-renderer", this);
  23. }else{
  24. nextObj = this;
  25. }
  26.  
  27. if(!($(" > div[id='dismissable']", nextObj).length)){
  28. return;
  29. }
  30.  
  31. nextObj = $(" > div[id='dismissable']", nextObj);
  32.  
  33. // Don't add the time span if it's already there
  34. if($(" > a > ytd-video-meta-block > div[id='metadata'] > div[id='metadata-line'] > span[id='time-since-upload']", nextObj).length){
  35. return;
  36. }
  37.  
  38. var rawLabel = $(" > a > h3 > span", nextObj).attr("aria-label");
  39. var regEx = /.*?\sby\s.*?\s((\d+)\s((year(s?))|(month(s?))|(week(s?))|(day(s?))|(hour(s?))|(minute(s?))|(second(s?))))\sago/;
  40. var timeSinceUpload = regEx.exec(rawLabel)[1];
  41. var timeSpan = "<span id=\"time-since-upload\" class=\"style-scope ytd-video-meta-block\">".concat(timeSinceUpload.concat("</span>"));
  42.  
  43. $(" > a > ytd-video-meta-block > div[id='metadata'] > div[id='metadata-line'] > span", nextObj).after(timeSpan);
  44. });
  45. }, 3000);