Last active
August 29, 2022 15:24
-
-
Save fydiog/500276a1125ae0be083ee3a11e78ebd1 to your computer and use it in GitHub Desktop.
Udemy show remaining time for current section in course
This file contains 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
//You can paste this function into the console and it will add a <span> with the remaining hours in your current section in your Udemy courses. | |
//You can also automate this script by creating a new Tampermonkey extension, just add this at the start of your extension | |
//Feel free to add any functionality (timeout, check if page is loaded..) this is just the base. | |
// ==UserScript== | |
// @name Udemy - Remaining hours for section | |
// @author Fidel Mangold | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Shows you the time remaining for | |
// @match *.udemy.com/* | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
function getTimeLeft() { | |
let sectionTitle; | |
document.querySelectorAll('div[class*=section--section]').forEach((item) => { | |
let checkBox = item.querySelector('span[id*=accordion-panel][data-checked="checked"]') | |
if(checkBox != null){ | |
let sectionH3 = checkBox.nextSibling.querySelector('h3[class*=udlite-accordion-panel-heading]') | |
sectionTitle = sectionH3.nextSibling | |
} | |
}) | |
let minutes = 0; | |
let hours = 0; | |
const items = document.querySelectorAll('.item-link.udlite-custom-focus-visible') | |
items.forEach((item) => { | |
const isChecked = item.querySelector('.udlite-real-toggle-input').checked; | |
if (!isChecked) { | |
let timer = item.querySelector('.udlite-text-xs span'); | |
if (timer) { | |
let time = timer.innerText.replace('min', ''); | |
minutes+= parseInt(time); | |
hours = minutes/60; | |
} | |
} | |
}) | |
sectionTitle.innerHTML += ` - <span style='color:#5624CC'> <b> ${Math.floor(hours)} h ${minutes % 60} min left </b><small>(${minutes} min)</small></span>`; | |
} | |
getTimeLeft(); |
Author
fydiog
commented
Mar 27, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment