Coursera Dual Subtitles Overlay / Coursera 双语字幕覆盖层脚本
A Tampermonkey userscript that enhances the Coursera video player by displaying dual-language subtitles in a highly customizable overlay. It replaces the native subtitle display to provide precise control over layout, font size, vertical position, and the spacing between subtitle lines.
一份油猴(Tampermonkey)脚本,它通过一个高度可定制的覆盖层(Overlay)来增强 Coursera 视频播放器的体验。脚本会接管并隐藏原生字幕,从而实现对字幕布局、字号、垂直位置、以及两行字幕间距的精确控制。
English
Features
- Custom Subtitle Overlay: Renders subtitles in a custom layer, enabling precise control that the native player doesn't offer.
- Top/Bottom Language Order: Displays the primary language (default: English) on top and the secondary language (default: Chinese) below.
- Fully Adjustable Layout:
- Font Size: Increase or decrease the font size in real-time.
- Vertical Position: Move the entire subtitle block up or down on the screen.
- Line Spacing: Fine-tune the gap between the two subtitle lines. Supports negative values for a tighter, overlapping fit.
- Persistent Settings: Your preferences for font size, position, and line spacing are automatically saved and applied to future videos.
- Seamless Integration: Adds a clean control panel to the Coursera header bar for easy access.
Installation
- Install a userscript manager: You need a browser extension like Tampermonkey (recommended), Violentmonkey, or Greasemonkey.
- Install the script: Click on the installation link from the script's homepage (e.g., on Greasy Fork镜像) and follow the prompts from your userscript manager.
Usage
- Navigate to any Coursera video page.
- A new control panel will appear in the header bar at the top-right of the page.
- Use the buttons to control the subtitles:
- 双语 (Dual): Toggle the dual-language subtitle overlay on or off.
- 字号 (Font Size): Use
+
and -
to adjust the size.
- 位置 (Position): Use
↑
and ↓
to move the subtitles vertically.
- 行距 (Line Gap): Use
+
and -
to control the space between the two subtitle lines.
Advanced Customization
You can easily change the default settings by editing the script:
/********* 可配置默认 *********/
const PRIMARY_LANG = 'en'; // Default top language
const SECONDARY_LANG = 'zh-CN'; // Default bottom language
const DEFAULT_BOTTOM_PERCENT= 8; // Initial vertical position (percentage from bottom)
const DEFAULT_FONT_SIZE = 130; // Initial font size (percentage)
const DEFAULT_LINE_GAP_EM = -0.05; // Initial gap between lines (in 'em' units)
/********************************/
Change the language codes (e.g., 'fr'
for French, 'es'
for Spanish) or numerical values to fit your needs.
中文
功能特性
- 自定义字幕覆盖层: 在一个独立的图层上渲染字幕,实现原生播放器无法做到的精细控制。
- 上英下中字幕顺序: 默认显示英文主字幕在上方,中文次字幕在下方。
- 完全可调节的布局:
- 字体大小: 实时增大或缩小字幕字号。
- 垂直位置: 在屏幕上整体上下移动字幕的位置。
- 字幕行距: 精确调整两行字幕之间的间距,支持负值以实现更紧凑的贴合效果。
- 持久化设置: 你的字号、位置、行距等偏好设置会被自动保存,并在观看其他视频时生效。
- 无缝集成: 在 Coursera 页面顶部的工具栏添加一个简洁的控制面板,方便操作。
安装步骤
- 安装用户脚本管理器: 你需要先安装一个浏览器扩展,如 Tampermonkey (篡改猴) (推荐)、Violentmonkey (暴力猴) 等。
- 安装本脚本: 从脚本发布页(如 Greasy Fork镜像)点击安装链接,你的脚本管理器会自动弹出并提示你安装。
使用方法
- 打开任意 Coursera 视频页面。
- 在页面右上角的顶部工具栏,你会看到一个新的控制面板。
- 使用这些按钮来控制字幕:
- 双语: 点击开启或关闭双语字幕覆盖层。
- 字号: 使用
+
和 -
按钮调整字体大小。
- 位置: 使用
↑
和 ↓
按钮来垂直移动字幕。
- 行距: 使用
+
和 -
按钮来控制中英文字幕之间的间隙。
高级自定义
你可以通过编辑脚本来轻松修改默认设置:
/********* 可配置默认 *********/
const PRIMARY_LANG = 'en'; // 默认上方语言
const SECONDARY_LANG = 'zh-CN'; // 默认下方语言
const DEFAULT_BOTTOM_PERCENT= 8; // 初始垂直位置 (距底部百分比)
const DEFAULT_FONT_SIZE = 130; // 初始字体大小 (百分比)
const DEFAULT_LINE_GAP_EM = -0.05; // 初始行距 (单位 'em', 可为负)
/********************************/
只需修改语言代码(例如,'fr'
代表法语, 'es'
代表西班牙语)或数字,即可满足你的个性化需求。
License / 许可协议
This script is released under the MIT License.
本脚本基于 MIT 许可证发布。