您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automatically likes a video or livestream on YouTube
当前为
// ==UserScript== // @name YouTube Auto Like // @namespace http://tampermonkey.net/ // @version 1.22 // @description Automatically likes a video or livestream on YouTube // @author Yukiteru // @match https://www.youtube.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @require https://gf.qytechs.cn/scripts/470224-tampermonkey-config/code/Tampermonkey%20Config.js // @license MIT // ==/UserScript== function printLog(message) { console.log(`[YouTube Auto Like]: ${message}`); } const config_desc = { ratio: { name: "Like after percentage", processor: "int_range-1-100", value: 50, }, only_sub: { name: "Only like subscribed channels", input: "current", processor: "not", formatter: "boolean", value: true, }, }; const config = new GM_config(config_desc); function getLikeButton() { return document.querySelector("like-button-view-model button"); } function getVideo() { return document.querySelector("video.html5-main-video"); } function isLiked() { return getLikeButton().getAttribute("aria-pressed") === "true"; } function isSubscribed() { const subscribeButton = document.querySelector("ytd-subscribe-button-renderer"); return subscribeButton.hasAttribute("subscribed"); } function shouldLike() { if (isSubscribed()) return true; return !config.get('only_sub'); } function isLivestream() { const liveBadge = document.querySelector(".ytp-live"); return liveBadge !== null; } function like() { if (isLiked()) printLog("user liked manually"); else getLikeButton().click(); getVideo().removeEventListener("timeupdate", listener); } function listener() { const video = getVideo(); const percentage = config.get('ratio') / 100; if (video.currentTime / video.duration > percentage && shouldLike()) { like(video); } } function findLikeButton() { const observer = new MutationObserver((mutations, observer) => { const likeButton = getLikeButton(); if (!likeButton) return; printLog("like button checked"); observer.disconnect(); if (!shouldLike()) return false; if (isLivestream() && shouldLike()) return like(); // like and exit if this is a livestream getVideo().addEventListener("timeupdate", listener); }); observer.observe(document, { childList: true, subtree: true }); } document.addEventListener("yt-navigate-finish", findLikeButton());
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址