Kick.com Video Resume

Automatically bookmarks Kick.com videos and resumes where you left off.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Kick.com Video Resume
// @namespace    https://greasyfork.org/users/1370822
// @version      1.0
// @description  Automatically bookmarks Kick.com videos and resumes where you left off.
// @author       HANT3R
// @license      MIT
// @match        https://kick.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let saveInterval = null;
    let lastSavedTime = 0;

    // Function to save video time to local storage every 5 seconds
    function saveVideoTime(video) {
        const videoId = window.location.pathname; // Get unique video URL or ID
        const currentTime = Math.floor(video.currentTime); // Round off to avoid excessive changes
        if (currentTime !== lastSavedTime) {
            localStorage.setItem(`kick_video_time_${videoId}`, currentTime);
            lastSavedTime = currentTime;
        }
    }

    // Function to load video time from local storage
    function loadVideoTime(video) {
        const videoId = window.location.pathname;
        const savedTime = localStorage.getItem(`kick_video_time_${videoId}`);
        if (savedTime) {
            video.currentTime = parseFloat(savedTime);
            console.log(`Resuming video from ${savedTime} seconds`);
        }
    }

    // Initialize video resume functionality
    function initVideoResume(video) {
        loadVideoTime(video);

        // Set an interval to save the video time every 5 seconds
        saveInterval = setInterval(() => saveVideoTime(video), 5000);

        // Also save when the video is paused
        video.addEventListener('pause', () => saveVideoTime(video));

        // Cleanup when video ends or is no longer available
        video.addEventListener('ended', () => clearInterval(saveInterval));
    }

    // Wait for the video element to load
    function onVideoLoad() {
        const video = document.querySelector('video');
        if (video && !video.hasAttribute('data-resume-init')) {
            video.setAttribute('data-resume-init', 'true'); // Prevent reinitialization
            video.addEventListener('loadeddata', () => initVideoResume(video), { once: true });
        }
    }

    // Observe DOM changes to detect when a new video loads
    const observer = new MutationObserver(onVideoLoad);
    observer.observe(document.body, { childList: true, subtree: true });

})();