Youtube - Auto Like

Auto likes a video near the end, the goal being to keep track of watched videos since youtube history is limited

目前為 2023-12-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube - Auto Like
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  Auto likes a video near the end, the goal being to keep track of watched videos since youtube history is limited
// @author       You
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==


function l(...args){
    console.log('[Auto Like]', ...args)
}

function getLikeButton(){
    return document.querySelector('#segmented-like-button button')
}

function isLiked(){
    return getLikeButton().getAttribute("aria-pressed") === 'true'
}

function like(){
    if(!isLiked()) getLikeButton().click()
}

function listen(video){
    l('listening', video)
    video.addEventListener('timeupdate', () => {
        if(video.currentTime/video.duration > 0.9){
            like()
        }
    })
}

function findVideo(onVideoFound){
    const observer = new MutationObserver((mutations, observer) => {
        // Keep trying to find video
        let video = document.querySelector('video.video-stream')
        if(video){
            onVideoFound(video)
            observer.disconnect()
        }
    })
    observer.observe(document, {childList:true, subtree:true})
}

findVideo(video => {
    listen(video)
})