YouTube Resume

Resume YouTube videos to where you left off.

当前为 2016-12-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Resume
// @namespace    https://greasyfork.org/en/users/88735-lacour
// @version      1.1
// @description  Resume YouTube videos to where you left off.
// @author       laCour
// @license      MIT
// @match        http*://www.youtube.com/*
// @exclude      http*://www.youtube.com/tv*
// @exclude      http*://www.youtube.com/live_chat*
// @run-at       document-end
// @grant        GM_getValue
// @grant        GM_setValue
// @noframes
// ==/UserScript==

(function() {
  "use strict";

  var player = document.getElementById("movie_player");

  if (typeof player === undefined || player === null) {
    console.warn("[Youtube Resume] Player not defined.");
    return;
  }

  var video_id = player.getVideoData().video_id;
  var video_duration = player.getDuration();

  function saved_progress() {
    return GM_getValue("p_" + video_id, 0);
  }

  function save_progress() {
    GM_setValue("p_" + video_id, player.getCurrentTime());
  }

  function resume_progress() {
    var resume_to = saved_progress();
    var should_resume = true;

    if (resume_to > 10) {
      resume_to -= 5;
    }

    if (video_duration > 0) {
      should_resume = (video_duration - resume_to) >= video_duration * 0.05;
    }

    if (should_resume) {
      player.seekTo(resume_to, true);
    }
  }

  if (player.getCurrentTime() < 2) {
    resume_progress();
  }

  if (video_duration > 2 || video_duration === 0) {
    setInterval(save_progress, 1500);
  }
})();