Set Youtube caption selectable, make it easy to quickly select and translate word in the caption for Mac
// ==UserScript== // @name:en Set Youtube caption selectable easy to quickly translate word for Mac // @name Youtube字幕单词可以直接选中,方便Mac电脑快速选中翻译单词 // @namespace http://tampermonkey.net/ // @version 1.4 // @description:en Set Youtube caption selectable, make it easy to quickly select and translate word in the caption for Mac // @description Youtube字幕单词可以直接选中,方便Mac电脑快速选中翻译单词(Mac触控板手势重按或三指轻点) // @author You // @match https://www.youtube.com/* // @icon https://www.google.com/s2/favicons?domain=youtube.com // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // Your code here... /** 检测DOM变动 */ const mutationDiv = document.body; const observer = new MutationObserver(callback); observer.observe(mutationDiv, { childList: true, // 观察直接子节点 subtree: true, // 及其更低的后代节点 attributes: true, characterData: true }); /** DOM变动的回调函数 */ function callback (mutationRecord) { const subtitle = document.querySelector('#ytp-caption-window-container'); const spanList = subtitle.querySelectorAll('span'); spanList.forEach(el => { el.style.userSelect = 'text'; }); }; })();