YouTube Absolute DateTime

Reveal when broadcast started

  1. // ==UserScript==
  2. // @name YouTube Absolute DateTime
  3. // @namespace https://i544c.github.com/
  4. // @match https://www.youtube.com/*
  5. // @grant none
  6. // @version 1.0.1
  7. // @author i544c
  8. // @description Reveal when broadcast started
  9. // @description:ja その配信がいつ始まったのかを明らかにする
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. 'use strict';
  14. const _debug = (...msg) => {
  15. console.log('[wdbs] ', ...msg);
  16. };
  17. const queryString = 'span[itemtype="http://schema.org/BroadcastEvent"] meta[itemprop="startDate"]';
  18. const main = async () => {
  19. _debug('start');
  20. // ページ内遷移した際にヘッダーが変わらないため、自身のページをfetchする
  21. const res = await fetch(window.location, { cache: 'no-cache' });
  22. const rawBody = await res.text();
  23. const domparser = new DOMParser();
  24. const body = domparser.parseFromString(rawBody, 'text/html');
  25. const startDateText = body.querySelector(queryString)?.getAttribute('content');
  26. if (!startDateText) return;
  27. const startDate = new Date(startDateText);
  28. _debug(startDate);
  29. document.querySelector('#info-text #date *:not(#dot)').innerText = startDate.toLocaleString();
  30. };
  31. document.addEventListener('yt-navigate-finish', main);
  32. })();