Youtube Resumer

Updates the url so that it contains "?t={time}" corresponding to video.currentTime.

当前为 2021-10-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Resumer
  3. // @description Updates the url so that it contains "?t={time}" corresponding to video.currentTime.
  4. // @version 1
  5. // @match https://www.youtube.com/watch?*
  6. // @grant none
  7. // @namespace https://greasyfork.org/users/206408
  8. // ==/UserScript==
  9.  
  10. (async () => {
  11.  
  12. function l(message){
  13. console.log(`[Youtube Resumer] ${message}`)
  14. }
  15.  
  16. l('starting')
  17.  
  18. const video = document.querySelector('video');
  19. video.addEventListener('timeupdate', (event) => {
  20. l(`duration changed: ${video.currentTime}`)
  21. const time = parseInt(video.currentTime)
  22. const url = new URL(window.location.href)
  23. url.searchParams.set('t', time)
  24. window.history.replaceState(null, null, url);
  25. })
  26. })();