12

Script to find Udemy Course remaining time

 2 years ago
source link: https://gist.github.com/jithurjacob/4af5e9e8d231d79f17f6e553ba166864
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Script to find Udemy Course remaining time · GitHub

Instantly share code, notes, and snippets.

Script to find Udemy Course remaining time

It's been awhile since I've been on Udemy, and I'm glad I came across some updates to the script.
Ended up fixing it a bit (updating selectors and logic), and published the next iteration: https://greasyfork.org/en/scripts/28295-udemy-show-section-time

Still has a weird bug where it's showing to many places for minutes (H:MMM:S), but it at least calcs the section times again tada

This no longer works : (

Can someone teach me how to fix this script? I would maintain it full-time.

edenizk commented on Jan 17

Tbh idk what does the above code do, but if someone wants to check how many mins left for their course
you can copy-paste the code below to your console in dev tools :)

function getLeftTime() {
  // Open all the sections
  console.log('Opening Sections...');
  document.querySelectorAll('.js-panel-toggler').forEach((item) => {
    const isExpanded = item.getAttribute('aria-expanded');
    if (!isExpanded) {
      item.click();
    }
  })
  console.log('Opening Sections DONE');

  console.log('Calculation Total ...')
  let total = 0;
  const items = document.querySelectorAll('.item-link.udlite-custom-focus-visible') // each item
  items.forEach((item) => {
    // console.log(item);
    const isChecked = item.querySelector('.udlite-real-toggle-input').checked;

    if (!isChecked) {
      let timer = item.querySelector('.udlite-text-xs span');
      if (timer) {
        time = timer.innerText.replace('min', '');
        // console.log('time', time);
        total+= parseInt(time);
      }
    }
  })
  console.log('Calculation Total DONE')

  console.log('left Time(Min): ', total);
}
getLeftTime()

An updated version that works:

(function getLeftTime() {
    const scrollTopValue = window.scrollY;

    // Opening unopened sections
    const unopened = [];
    document
        .querySelectorAll('.section--section--BukKG > span')
        .forEach((item) => {
            const isExpanded = item.getAttribute('data-checked') === 'checked';
            if (!isExpanded) {
                item.parentNode
                    .querySelector('.udlite-accordion-panel-title')
                    .click();
                unopened.push(item);
            }
        });

    // Calculating total
    let total = 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) {
                time = timer.innerText.replace('min', '');
                total += parseInt(time);
            }
        }
    });

    unopened.forEach((item) =>
        item.parentNode.querySelector('.udlite-accordion-panel-title').click()
    );
    window.scrollTo({ top: scrollTopValue });

    const hourString =
        total / 60.0 < 10
            ? '0' + String(Math.trunc(total / 60.0))
            : String(Math.trunc(total / 60.0));
    const minuteString =
        total % 60.0 < 10
            ? '0' + String(Math.trunc(total % 60.0))
            : String(Math.trunc(total % 60.0));

    console.log(`Time left (HH:MM): ${hourString}:${minuteString}`);
})();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK