激活 youtube 字幕时,如果您尝试在 DOM 中由 id="caption-window-1"
标识的字幕中选择一个单词,首先注意到的是:它是不可选的,所以为了让它可选,我使用 chrome 浏览器上的开发者工具在 js 控制台中运行这个脚本:
(function() {
var caption= document.getElementById("caption-window-1");
caption.style.cursor="text";
caption.style["-webkit-user-select"]="all";
})();
轮到完美了,但是点击它时标题仍在移动(您可以在YouTube上自行尝试)
所以我不能轻易地在标题中选择一个词,它仍然在移动我所做的任何事情。
我想禁用 onclick 事件上的标题移动有什么想法可以使用 javascript 来解决这个问题吗?
最佳答案
在控制台中运行此脚本:
setInterval(make_subtitles_selectable, 250);
function make_subtitles_selectable(){
elem=document.querySelector("span.ytp-caption-segment:not([selectable='true']");
if(elem!=null){
elem.style.userSelect="text";
elem.style.cursor="text";
elem.setAttribute("selectable", "true");
}
elem=document.querySelector("#caption-window-1:not([selectable='true']");
if(elem!=null){
elem.addEventListener("mousedown", function (event) {
event.stopPropagation();
}, true);
elem.setAttribute("selectable", "true");
}
}
关于javascript - 如何使 youtube 字幕可选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40165879/