YouTube - URL Playtime Keeper

Updates the browser URL with the current timestamp every 30 seconds so playback resumes where you left if you restart the browser,

  1. // ==UserScript==
  2. // @name YouTube - URL Playtime Keeper
  3. // @namespace https://github.com/ChemaZapiens/dev/tree/main/random/userscript
  4. // @version 01
  5. // @description Updates the browser URL with the current timestamp every 30 seconds so playback resumes where you left if you restart the browser,
  6. // @description bookmark the video, use The Greater Discarder, etc.
  7. // @description You can also quickly copy the URL or modify the time (&t=1m30s)
  8. // @author Chema Zapiens
  9. // @license GPL 3.0
  10. // @match *://www.youtube.com/watch*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function formatTime(seconds) {
  18. const minutes = Math.floor(seconds / 60);
  19. const secs = seconds % 60;
  20. return `${minutes}m${secs}s`;
  21. }
  22.  
  23. function updateUrlWithTimestamp() {
  24. const player = document.querySelector('video');
  25. if (!player) return;
  26.  
  27. const currentTime = Math.floor(player.currentTime);
  28. const formattedTime = formatTime(currentTime);
  29. const url = new URL(window.location.href);
  30.  
  31. if (url.searchParams.get('t') !== formattedTime) {
  32. url.searchParams.set('t', formattedTime);
  33. window.history.replaceState(null, '', url.toString());
  34. }
  35. }
  36.  
  37. setInterval(updateUrlWithTimestamp, 30000);
  38. })();

QingJ © 2025

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