-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
52 lines (46 loc) · 1.79 KB
/
background.js
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
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (!tab.url) {
return
}
if (!tab.url.startsWith("https://udemy.com") && !tab.url.startsWith("https://www.udemy.com")) {
return
}
chrome.scripting.executeScript({
target: {
tabId: tab.id, allFrames: false,
}, injectImmediately: false, world: 'MAIN', func: () => {
let firstTime = true;
if (window.__udemyCaptionLockerInterval !== undefined) {
return
}
window.__udemyCaptionLockerInterval = setInterval(() => {
const scriptDisabled = localStorage.getItem("__udemy-caption-locker__disabled")
if (scriptDisabled) {
return
}
let transcriptToggle = document.querySelector("[data-purpose=transcript-toggle]")
if (!transcriptToggle) {
return
}
let transcriptPanel = document.querySelector("[data-purpose=transcript-panel]")
if (!transcriptPanel) {
if (firstTime) {
firstTime = false
transcriptToggle.click()
}
return
}
firstTime = false
let activeTranscript = document.querySelector("[data-purpose=transcript-cue-active]")
if (!activeTranscript) {
return
}
let activeCaption = document.querySelector("[data-purpose=captions-cue-text]");
if (!activeCaption) {
return
}
activeCaption.textContent = activeTranscript.textContent;
}, 250)
}, args: [tab]
})
});