-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-transcript.user.js
More file actions
53 lines (44 loc) · 1.77 KB
/
auto-transcript.user.js
File metadata and controls
53 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ==UserScript==
// @name Auto Show Transcript
// @namespace https://youtube.com
// @version 1.0
// @description transcripts go brr
// @match https://www.youtube.com/watch*
// @updateURL https://raw.githubusercontent.com/vegcom/scripty-scripts/main/auto-transcript.user.js
// @downloadURL https://raw.githubusercontent.com/vegcom/scripty-scripts/main/auto-transcript.user.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
const delay = ms => new Promise(r => setTimeout(r, ms));
async function showTranscript() {
// wait for page to actually render
await delay(1500);
// check if transcript panel already open
if (document.querySelector('ytd-transcript-segment-list-renderer')) {
console.log('📜 transcript already open');
return;
}
// expand description first (transcript button lives there now)
const expandBtn = document.querySelector('tp-yt-paper-button#expand');
if (expandBtn) {
expandBtn.click();
await delay(300);
}
// find and click "Show transcript"
const buttons = document.querySelectorAll('ytd-video-description-transcript-section-renderer button');
const transcriptBtn = [...buttons].find(b => b.textContent.includes('Show transcript'));
if (transcriptBtn) {
transcriptBtn.click();
console.log('📜 transcript opened~');
} else {
console.log('📜 no transcript available for this video');
}
}
// handle yt spa navigation
window.addEventListener('yt-navigate-finish', showTranscript);
// also run on initial load
if (window.location.pathname === '/watch') {
showTranscript();
}
})();