您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Enables keyboard shortcuts to like/dislike a video on YouTube.
// ==UserScript== // @name YouTube Like/Dislike Shortcuts Lite // @name:pt-BR Atalhos Gostei/Não Gostei Lite no YouTube // @namespace YTLDSL // @author warib64 // @description Enables keyboard shortcuts to like/dislike a video on YouTube. // @description:pt-BR Cria atalhos para os botões gostei/não gostei em um vídeo no YouTube. // @match *://*.youtube.com/* // @license MIT // @version 1.2 // ==/UserScript== // You can change the codes to whichever keys you want to use for liking, disliking, and opening or writing comments on Shorts. const codeLike = "NumpadAdd"; const codeDislike = "NumpadSubtract"; /* Filling in these quotation marks with the code of a key creates an additional shortcut dedicated to removing your like/dislike, that makes it so that pressing the regular shortcuts for liking/disliking multiple times has no effect on the state of that button. If you want to use the regular shortcuts for removing likes/dislikes as well, leave this blank. */ const codeRemove = ""; // If you want the shortcut to be triggered only when holding ctrl, alt, or shift, change this value from 0 to 1, 2, or 3, respectively. const combination = 0; // /\/\/\ Settings /\/\/\ // ------------------------------ // \/\/\/ Code \/\/\/ let tag, like, dislike; const observer = new MutationObserver(findButtons); addEventListener('yt-page-data-updated', reset); function reset() { isVideo = /^\/watch/.test(location.pathname); if (isVideo) { removeEventListener("keydown", press); like = null; dislike = null; observer.observe(document.documentElement, {childList: true, subtree: true}); findButtons(); } } function findButtons() { if (like && dislike) { addEventListener("keydown", press); observer.disconnect(); } like = document.querySelector('like-button-view-model button'); dislike = document.querySelector('dislike-button-view-model button'); } function press(e) { if (e.target.getAttribute("contenteditable") === "true") {return;} tag = e.target.tagName.toLowerCase(); if (tag === "input" || tag === "textarea") {return;} switch (combination) { case 1: if (!e.ctrlKey) {return;} break; case 2: if (!e.altKey) {return;} break; case 3: if (!e.shiftKey) {return;} break; } switch (e.code) { case codeLike: if (like) { if (codeRemove && checkPressed(like)) {break;} else {like.click();} } case codeDislike: if (dislike) { if (codeRemove && checkPressed(dislike)) {break;} else {dislike.click();} } break; case codeRemove: if (checkPressed(like)) {like.click();} else if (checkPressed(dislike)) {dislike.click();} break; } } function checkPressed(element) { return (element.getAttribute("aria-pressed") === "true"); }
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址