YouTube - Remaining Time Indicator

Displays the remaining duration of a YouTube video next to the video duration, taking into account the playback rate.

安裝腳本?
作者推薦腳本

您可能也會喜歡 YouTube - Playback Speed Slider

安裝腳本
  1. // ==UserScript==
  2. // @name YouTube - Remaining Time Indicator
  3. // @name:fr YouTube - Indicateur du temps restant
  4. // @name:es YouTube - Indicador de tiempo restante
  5. // @name:de YouTube - Anzeige der verbleibenden Zeit
  6. // @name:it YouTube - Indicatore del tempo rimanente
  7. // @name:zh-CN YouTube - 剩余时间指示器
  8. // @namespace https://gist.github.com/4lrick/cf14cf267684f06c1b7bc559ddf2b943
  9. // @version 1.8
  10. // @description Displays the remaining duration of a YouTube video next to the video duration, taking into account the playback rate.
  11. // @description:fr Affiche la durée restante d'une vidéo YouTube à côté de la durée de la vidéo, en tenant compte de la vitesse de lecture.
  12. // @description:es Muestra la duración restante de un video de YouTube junto a la duración del video, teniendo en cuenta la velocidad de reproducción.
  13. // @description:de Zeigt die verbleibende Dauer eines YouTube-Videos neben der Videodauer an und berücksichtigt dabei die Wiedergabegeschwindigkeit.
  14. // @description:it Mostra la durata rimanente di un video di YouTube accanto alla durata del video, tenendo conto della velocità di riproduzione.
  15. // @description:zh-CN 在视频时长旁边显示YouTube视频的剩余时长,考虑播放速度。
  16. // @author 4lrick
  17. // @match https://www.youtube.com/*
  18. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  19. // @grant none
  20. // @license GPL-3.0-only
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. 'use strict';
  25. let timeDisplay;
  26.  
  27. function displayRemainingTime() {
  28. const videoElement = document.querySelector('video');
  29.  
  30. if (videoElement) {
  31. const timeRemaining = (videoElement.duration - videoElement.currentTime) / videoElement.playbackRate;
  32. const hours = Math.floor(timeRemaining / 3600);
  33. const minutes = Math.floor((timeRemaining % 3600) / 60);
  34. const seconds = Math.floor(timeRemaining % 60);
  35. const isLive = document.querySelector('.ytp-time-display').classList.contains('ytp-live');
  36.  
  37. if (!isLive) {
  38. timeDisplay.textContent = `(${hours > 0 ? `${hours}:` : ''}${minutes < 10 ? '0' : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds})`;
  39. } else {
  40. timeDisplay.textContent = null;
  41. }
  42. }
  43. requestAnimationFrame(displayRemainingTime);
  44. }
  45.  
  46. function initDisplay() {
  47. timeDisplay = document.createElement('div');
  48. timeDisplay.style.display = 'inline-block';
  49. timeDisplay.style.marginLeft = '10px';
  50. timeDisplay.style.color = '#ddd';
  51.  
  52. const timeContainer = document.querySelector('.ytp-time-display');
  53.  
  54. if (timeContainer) {
  55. timeContainer.appendChild(timeDisplay);
  56. requestAnimationFrame(displayRemainingTime);
  57. observer.disconnect();
  58. }
  59. }
  60.  
  61. function checkVideoExists() {
  62. const videoElement = document.querySelector('video');
  63.  
  64. if (videoElement) {
  65. initDisplay();
  66. }
  67. }
  68.  
  69. const observer = new MutationObserver(checkVideoExists);
  70. const body = document.body;
  71. const config = { childList: true, subtree: true };
  72. observer.observe(body, config);
  73. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址