// ==UserScript==
// @name YouTube 自动设置中文字幕
// @match *://youtube.com/*
// @match *://*.youtube.com/*
// @author kernelpanic
// @description 自动设置中文字幕,如果没有则自动选择英文->简体中文翻译
// @icon https://www.youtube.com/favicon.ico
// @noframes
// @run-at document-idle
// @version 1.0
// ==/UserScript==
(() => {
let main = function(event) {
if (event !== undefined && event.target.numNavigations_ == 0) {
return;
}
if (!/\/(watch)/.test(window.location.pathname)) {
return;
}
let player = document.querySelector('.html5-video-player');
player.toggleSubtitles();
var trackList = player.getOption('captions', 'tracklist');
if (trackList === undefined) {
console.log('本视频不支持字幕或翻译!');
return;
}
var availableTracks = trackList.map(track => track.languageCode);
console.log(`支持的字幕: ${availableTracks}`)
if(availableTracks.includes('zh-Hans')){
console.log('有中文字幕,直接加载!');
player.setOption('captions', 'track', {languageCode: 'zh-Hans'});
}else{
console.log('没有中文字幕,设置自动翻译');
player.setOption('captions', 'track', {"languageCode":"en","languageName":"英语","displayName":"英语","kind":"","name":null,"id":null,"is_servable":false,"is_default":false,"is_translateable":true,"vss_id":".en","translationLanguage":{"languageCode":"zh-Hans","languageName":"中文(简体)"}});
}
}
window.addEventListener('yt-navigate-finish', main);
})();
1
liyang5945 2023-04-04 13:36:25 +08:00
不错,支持
|
2
zhangsimon 2023-04-04 14:42:33 +08:00
不错
lz 方不方便写一个百度网盘的分享设置脚本 百度网盘分享时每次都要选择日期和设置密码 想要一个自己设置的密码和长期有效 直接分享并复制到剪切板😮💨 |
3
chonger 2023-04-04 14:43:45 +08:00
很实用,谢谢~
|
4
mailhanzhong 2023-04-04 14:53:47 +08:00
好人一生平安
|
5
AoEiuV020CN 2023-04-04 16:47:58 +08:00 1
没有发布到那个网站上吗?
或者至少可以发布到 github 上, 不太想复制粘贴添加脚本, |
6
garywill 2023-04-05 21:54:44 +08:00 1
我写过个显示任意多字个幕的,可以搞中英对照 https://github.com/garywill/multi-subs-yt
楼主这个用 player 来获取配置信息的方案以前也用过,但后来改掉了,因为发现切换视频后,player 信息不更新 https://github.com/1c7/Youtube-Auto-Subtitle-Download/issues/15 |
7
s609926202 2023-04-07 13:44:59 +08:00
赞
|
8
s609926202 2023-04-07 13:50:21 +08:00
可惜不支持移动端
|