Last active
November 15, 2024 21:28
-
-
Save zevaverbach/2f8639ccb2c5c58ce707027cc3657b0a to your computer and use it in GitHub Desktop.
Get remaining time in a Teachable course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I created this for (and tested it on) a learn.cantrill.io course | |
// to quickly determine how much more video I have left to finish the course, | |
// so I could plan my time in advance of an AWS exam. | |
function getTotalMinutesLeftInCourse() { | |
let totalMinutes = 0; | |
for (const chapter of getChapters()) { | |
if (!chapterIsComplete(chapter)) { | |
const [minutes, seconds] = getMinutesAndSeconds(getLengthString(chapter.innerText)) | |
totalMinutes += (minutes + (seconds / 60)) | |
} | |
} | |
return totalMinutes | |
} | |
function getChapters() { | |
return document.querySelectorAll(".title-container"); | |
} | |
function chapterIsComplete(chapter) { | |
return chapter.previousElementSibling.getAttribute("aria-label") === "Completed item" | |
} | |
function getLengthString(string) { | |
const lengthString = string.match(/\d:\d\d/) | |
if (lengthString == null) { | |
// this only happens with quizzes, which is accurate | |
console.log(string, 'no match for length'); | |
return "0:00" | |
} | |
return lengthString[0]; | |
} | |
function getMinutesAndSeconds(lengthString) { | |
let [minutes, seconds] = lengthString.split(":") | |
return [parseInt(minutes), parseInt(seconds)] | |
} | |
function getChapterThisManyHoursFromWhereIAmCurrently(hours) { | |
let totalMinutes = 0; | |
for (const chapter of getChapters()) { | |
if (!chapterIsComplete(chapter)) { | |
const [minutes, seconds] = getMinutesAndSeconds(getLengthString(chapter.innerText)) | |
totalMinutes += (minutes + (seconds / 60)) | |
if (totalMinutes >= (hours * 60)) { | |
return [totalMinutes, chapter.innerText] | |
} | |
} | |
} | |
} | |
function howManyHoursUntilChapter(chapterNameSubstring) { | |
let totalMinutes = 0; | |
for (const chapter of getChapters()) { | |
if (!chapterIsComplete(chapter)) { | |
const chapterText = chapter.innerText; | |
if (chapterText.includes(chapterNameSubstring)) { | |
return totalMinutes / 60; | |
} | |
const [minutes, seconds] = getMinutesAndSeconds(getLengthString(chapterText)); | |
totalMinutes += (minutes + (seconds / 60)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment