Skip to content

Instantly share code, notes, and snippets.

@fydiog
Last active August 29, 2022 15:24
Show Gist options
  • Save fydiog/500276a1125ae0be083ee3a11e78ebd1 to your computer and use it in GitHub Desktop.
Save fydiog/500276a1125ae0be083ee3a11e78ebd1 to your computer and use it in GitHub Desktop.
Udemy show remaining time for current section in course
//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();
@fydiog
Copy link
Author

fydiog commented Mar 27, 2022

be09cdea7aa0f4752d9612e7725075ee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment