Greasy Fork镜像 支持简体中文。

Youtube Resumer (using the url)

Changes the ?t= parameter when pausing. Other version: https://gf.qytechs.cn/en/scripts/455475-youtube-resumer

  1. // ==UserScript==
  2. // @name Youtube Resumer (using the url)
  3. // @description Changes the ?t= parameter when pausing. Other version: https://gf.qytechs.cn/en/scripts/455475-youtube-resumer
  4. // @version 4
  5. // @match https://www.youtube.com/*
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  7. // @grant none
  8. // @namespace https://gf.qytechs.cn/users/206408
  9. // ==/UserScript==
  10.  
  11. (async () => {
  12.  
  13. function l(...args){
  14. console.log(`[Youtube Resumer]`, ...args)
  15. }
  16.  
  17. function findVideo(){
  18. return document.querySelector('video')
  19. }
  20.  
  21. //update ?t=
  22. function changeUrl(time){
  23. const url = new URL(window.location.href)
  24. url.searchParams.set('t', time)
  25. window.history.replaceState(null, null, url)
  26. }
  27.  
  28. function listen(){
  29. const video = findVideo()
  30. video.addEventListener('pause', () => {
  31. changeUrl(parseInt(video.currentTime))
  32. })
  33. }
  34.  
  35. let listening = false //the video element exists even if you go back to the home page, so no need to readd event listeners
  36.  
  37. //Event for each page change
  38. document.addEventListener("yt-navigate-finish", function() {
  39. l('navigate-finish')
  40. //Match page with video
  41. if(window.location.href.match(new RegExp('https://www.youtube.com/watch\\?v=.'))) {
  42. //Add video listener once
  43. if(!listening){
  44. l('listening')
  45. listen()
  46. listening = true
  47. }
  48. }
  49. });
  50. })();

QingJ © 2025

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