Youtube - Resume

Automatically start videos from where it stopped.

目前為 2023-11-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube - Resume
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      2
// @description  Automatically start videos from where it stopped.
// @author       hacker09
// @match        https://*.youtube.com/embed/*
// @match        https://www.youtube.com/watch?v=*
// @icon         https://www.youtube.com/s/desktop/03f86491/img/favicon.ico
// @run-at       document-end
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_listValues
// @grant        GM_deleteValue
// ==/UserScript==

(function() {
  'use strict';
  document.querySelector('video').addEventListener('timeupdate', function() { //When the video is playing
    if (this.currentTime >= 5) { //If 5 or more secs have passed
      GM_setValue(ytcfg.data_.VIDEO_ID === undefined ? document.querySelector('[video-id]').getAttribute('video-id') : ytcfg.data_.VIDEO_ID,{ "Last_Watched": new Date().getTime(), "StoppedAt": parseInt(this.currentTime)}); //Save the watched time
    } //Finishes the if condition
  }); //Finishes the Resume function

  GM_listValues().forEach(function(VidIDs) { //ForEach saved watched video time
    if ((GM_getValue(VidIDs, {}).Last_Watched) < (new Date().getTime() - 30 * 24 * 60 * 60 * 1000)) { //If 30+ days passed since the video was watched
      GM_deleteValue(VidIDs); //Delete the old saved watched video time
    }}); //Finishes the ForEach loop

  window.addEventListener('popstate', function() { document.querySelector('video').currentTime = GM_getValue(ytcfg.data_.VIDEO_ID === undefined ? document.querySelector("meta[itemprop='identifier']").content : ytcfg.data_.VIDEO_ID, {}).StoppedAt; }); //Auto Resume if the video url changes
  document.querySelector('video').currentTime = GM_getValue(ytcfg.data_.VIDEO_ID === undefined ? document.querySelector("meta[itemprop='identifier']").content : ytcfg.data_.VIDEO_ID, {}).StoppedAt; //Auto Resume the video onload
})();