Skip to content

Commit 58821eb

Browse files
committed
Update to account for new placement of transcript button
1 parent cee999d commit 58821eb

File tree

2 files changed

+8
-45
lines changed

2 files changed

+8
-45
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# yt-sub-search-keybind
22

3-
A Chrome extension for YouTube to have cmd/ctrl + F automatically open the subtitle pane. This way, your browser page search hops right into searching for a term within the subtitles of the video.
3+
A Chrome extension for YouTube to have cmd/ctrl + F automatically open the transcript pane. This way, your browser page search hops right into searching for a term within the subtitles of the video.
44

55
If you often find yourself manually opening up the subtitle pane so that you can cmd+F to jump to a spot in the video discussing a specific term, you might find this useful.
66

7-
### Example
8-
9-
<img height=400 src="https://user-images.githubusercontent.com/6415223/188805937-f7550a8a-4d4d-4b8c-ada0-6fb34847864c.gif">
10-
117
### Installation
128

139
1. Clone this repository: `git clone https://github.com/brentjo/yt-sub-search-keybind.git`

youtube-cmd-f.js

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,16 @@ document.body.addEventListener("keydown", function (event) {
1616
if (transcriptPaneNodes.length != 1) return;
1717
if (transcriptPaneNodes[0].getAttribute("visibility") != "ENGAGEMENT_PANEL_VISIBILITY_HIDDEN") return;
1818

19-
// Find the the elements to click that will open the transcript ("..." button -> "Show transcript")
20-
const primaryVideoInfoNode = document.querySelectorAll("ytd-menu-renderer.ytd-video-primary-info-renderer")
21-
if (primaryVideoInfoNode.length != 1) {
22-
console.error(UNEXPECTED_PAGE_STRUCTURE_ERR_MSG)
19+
// Find the 'Show transcript' button within the ytd-button-renderer element
20+
const outerYtdButtonRenderer = document.querySelector('ytd-button-renderer.ytd-video-description-transcript-section-renderer')
21+
if (!outerYtdButtonRenderer) {
22+
console.error(UNEXPECTED_PAGE_STRUCTURE_ERR_MSG);
2323
return;
2424
}
2525

26-
const moreActionsNode = primaryVideoInfoNode[0].querySelectorAll("yt-icon-button.dropdown-trigger.ytd-menu-renderer")[0]
27-
if (!moreActionsNode || moreActionsNode.children.length != 2 || (moreActionsNode.children > 0 && moreActionsNode.children[0].getAttribute("aria-label") != "More actions")) {
28-
console.error(UNEXPECTED_PAGE_STRUCTURE_ERR_MSG)
29-
return;
26+
const showTranscriptButton = outerYtdButtonRenderer.querySelector('button:only-child')
27+
if(showTranscriptButton && showTranscriptButton.innerText == "Show transcript"){
28+
showTranscriptButton.click();
3029
}
31-
32-
moreActionsNode.click();
33-
34-
// Wait until the "Show transcript" button is ready to click
35-
const msPollDuration = 20;
36-
let msSpentWaiting = 0;
37-
const checkButtonExistsInterval = setInterval(function () {
38-
msSpentWaiting += msPollDuration;
39-
40-
if (msSpentWaiting > 1000) {
41-
clearInterval(checkButtonExistsInterval);
42-
return;
43-
}
44-
45-
if (document.querySelectorAll("ytd-menu-service-item-renderer").length > 0) {
46-
clearInterval(checkButtonExistsInterval);
47-
const moreActionNodes = document.querySelectorAll("ytd-menu-service-item-renderer");
48-
49-
if (moreActionNodes.length == 0) {
50-
console.error(UNEXPECTED_PAGE_STRUCTURE_ERR_MSG);
51-
return;
52-
}
53-
54-
for (const actionNode of moreActionNodes) {
55-
if (actionNode.innerText == "Show transcript") {
56-
actionNode.click();
57-
break;
58-
}
59-
}
60-
61-
}
62-
}, msPollDuration);
6330
}
6431
});

0 commit comments

Comments
 (0)