您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Turn English subtitles on/off with the 'C' key.
// ==UserScript== // @name Coursera Subtitles Toggle // @description Turn English subtitles on/off with the 'C' key. // @namespace http://tampermonkey.net/ // @version 0.4 // @author Elias // @match *://www.coursera.org/learn/* // @match *://www.coursera.org/lecture/* // @grant none // @run-at document-idle // @license MIT // ==/UserScript== (function () { 'use strict'; // If using another subtitle, change the value const defaultSub = 'en'; let subtitlesEnabled = true; let englishSubtitleTrack = null; document.addEventListener('keydown', (e) => { if (e.code === 'KeyC' && englishSubtitleTrack) { subtitlesEnabled = !subtitlesEnabled; englishSubtitleTrack.mode = subtitlesEnabled ? 'showing' : 'disabled'; } }); const setupSubtitleTrack = (video) => { const track = Array.from(video.textTracks).find(t => t.language === defaultSub); if (track) { englishSubtitleTrack = track; englishSubtitleTrack.mode = subtitlesEnabled ? 'showing' : 'disabled'; } }; const handleMutations = (mutationsList, observer) => { mutationsList.forEach((mutation) => { if (mutation.type === 'childList') { mutation.addedNodes.forEach((node) => { if (node.nodeName === 'VIDEO') { const video = node; if (video.readyState >= 1) { setupSubtitleTrack(video); } else { video.addEventListener('loadedmetadata', () => setupSubtitleTrack(video), {once: true}); } } }) } }) }; const observer = new MutationObserver(handleMutations); observer.observe(document.body, {childList: true, subtree: true}); })();