YouTube Subtitle Downloader (Manual Trigger) with TrustedHTML Bypass and Spinner in Polymer Element

Fetch subtitles as SRT with manual trigger, bypass TrustedHTML policy, and insert a button (with spinner) into a Polymer dropdown element

目前為 2025-03-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
lihuelworks
評價
0 0 0
版本
1.3
建立日期
2025-03-13
更新日期
2025-03-13
尺寸
8.6 KB
授權條款
MIT
腳本執行於

YouTube Subtitle Downloader (Manual Trigger) with TrustedHTML Bypass

Overview

This user script allows you to view YouTube video subtitles in SRT format with a manual trigger. It fetches the most default subtitles (auto-generated or the first available track) using the YouTube API and opens them in a new tab. The script bypasses YouTube's TrustedHTML policy and inserts a button with a spinner into the Polymer dropdown element (as seen in the image below).

Polymer Dropdown Example

Features

  • Manual Trigger: Click the "Transcription" button to view subtitles.
  • TrustedHTML Bypass: Handles YouTube's TrustedHTML policy to extract subtitles.
  • Polymer Button with Spinner: A button with a spinner is injected into the YouTube interface's Polymer dropdown element.
  • Google API Integration: Uses the YouTube Data API to fetch the video captions (auto-subtitles or the first available subtitle track).

How It Works

  1. The script fetches the subtitles for the current video using the YouTube API.
  2. It extracts the default subtitle track (auto-generated or the first available).
  3. The subtitles are converted to SRT format and opened in a new tab for viewing (not for downloading, though I'm working on it).
  4. A spinner is displayed while the subtitles are being fetched.

Caveats

  • Editing Polymer is horrible: YouTube's Polymer elements can make dynamic content injection challenging. If any errors happen please let me know.
  • Pop-up Blockers: Ensure pop-ups are allowed for the download to work properly.
  • No Download: This script only displays subtitles in a new tab; it does not download them.

Installation

  1. Install Violentmonkey (or compatible userscript manager).
  2. Add this script to your userscript manager.
  3. Visit any YouTube video, click the button seen in the image above and click the "Transcription" button to view subtitles.

Credits

  • Thanks to Bret Donald for the solution that saved my life!