Get Youtube current Seconds

Get Youtube current Seconds!

目前為 2024-06-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Get Youtube current Seconds
// @namespace    http://tampermonkey.net/
// @version      2024-03-27
// @description  Get Youtube current Seconds!
// @author       fengxxc
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    function getSeconds(timestamp) {
        const sp = timestamp.split(":").map(Number)
        let seconds = 0
        for (let i = 0; i < sp.length; i++) {
            seconds += sp[i] * (60 ** (sp.length - i - 1))
        }
        return seconds
    }

    let btn = null
    let intervalId = setInterval(() => {
        if (btn != null) {
            clearInterval(intervalId)
            console.log(btn)
            btn.onclick = () => {
                const currenttime = document.querySelector('.ytp-time-current').innerText
                const currentSeconds = getSeconds(currenttime)
                const url = `${window.location.href}&t=${currentSeconds}s`
                console.log(`Now Play: ${currenttime}, seconds: ${currentSeconds}, url: ${url}`)
                navigator.clipboard.writeText(url).then(() => {
                    console.log('url copied to clipboard');
                }).catch(err => {
                    console.error('Failed to copy text: ', err);
                });
            }
        }
        btn = document.querySelector('#above-the-fold > #title')
    }, 60)



})();