Skip to content
This repository was archived by the owner on Aug 28, 2021. It is now read-only.

Commit 03835e8

Browse files
committed
cleanup finding source data from html page
1 parent 8a627be commit 03835e8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

app/src/background.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
async function getDownloadLink({lessonID, lessonName}, echo360Domain, downloadHD) {
2-
const regex = /(?:\(\")(?:.*)(?:\"\))/;
2+
const classroomAppRegex = new RegExp('(classroomApp)');
3+
const dataRegex = /(?:\(\")(?:.*)(?:\"\))/;
34
const lessonHTMLPageRequest = new Request(`${echo360Domain}/lesson/${lessonID}/classroom`, { method: 'GET', credentials: 'include' });
45
const lessonHTMLPageResponse = await fetch(lessonHTMLPageRequest)
56
const lessonHTMLPageText = await lessonHTMLPageResponse.text();
67
const dummyEl = document.createElement('html')
78
dummyEl.innerHTML = lessonHTMLPageText;
9+
const videoDataScript = Array.from(dummyEl.getElementsByTagName('script')).filter((script) => classroomAppRegex.test(script.innerText));
810

9-
const videoDataString = dummyEl.getElementsByTagName('script')[11].innerText.match(regex)[0]
11+
if (videoDataScript.length === 0)
12+
{
13+
return null;
14+
}
15+
16+
const videoDataString = videoDataScript[0].innerText.match(dataRegex)[0];
17+
1018
const cleanString = videoDataString.substring(1, videoDataString.length - 1);
1119
const videoDataObject = JSON.parse(JSON.parse(cleanString));
1220

0 commit comments

Comments
 (0)