Youtube - Auto Like

Auto likes a video after watching it, the goal being to keep track of watched videos since youtube history is limited

当前为 2022-11-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube - Auto Like
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Auto likes a video after watching it, 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(){ //when going to a new page, this might return the value of the old page
    return getLikeButton().ariaPressed === 'true'
}

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

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

}

const observer = new MutationObserver((mutations, observer) => {
    //Keep trying to find video
    let video = document.querySelector('video')
    if(video){
        listen(video)
        observer.disconnect() //video found
    }
})

observer.observe(document, {childList:true, subtree:true})