Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Created March 2, 2024 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiiragi/f694c649d21c27978f05f9b812c4c261 to your computer and use it in GitHub Desktop.
Save s-hiiragi/f694c649d21c27978f05f9b812c4c261 to your computer and use it in GitHub Desktop.
(YouTube) DVRでズレている時にメッセージを表示
javascript:(()=>{
const eVideo = document.querySelector('video.video-stream');
const eProgressBar = document.querySelector('.ytp-progress-bar');
const eMessage = document.createElement('div');
eMessage.style.cssText = 'color: red; font-size: 16px;';
const eContainer = document.querySelector('#chat-container');
eContainer.parentNode.insertBefore(eMessage, eContainer.nextSibling);
const makeLagMessage = (s) => `リアルタイムから${s}秒ズレています。`;
const handler = () => {
const now = parseInt(eProgressBar.getAttribute('aria-valuenow'));
const max = parseInt(eProgressBar.getAttribute('aria-valuemax'));
const eps = 5;
const delta = Math.abs(max - now);
eMessage.textContent = (delta > eps) ? makeLagMessage(delta) : '';
};
eVideo.addEventListener('play', handler);
eVideo.addEventListener('seeked', handler);
eVideo.addEventListener('timeupdate', handler);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment