Skip to content

Instantly share code, notes, and snippets.

@CodeDraken
Last active July 22, 2021 18:09
Show Gist options
  • Save CodeDraken/5a378e1e53a2637b3df53a1e08769843 to your computer and use it in GitHub Desktop.
Save CodeDraken/5a378e1e53a2637b3df53a1e08769843 to your computer and use it in GitHub Desktop.
Run this on a course page to get the date the course was created and last updated.
function getCourseId() {
const courseEl = document.querySelector("body#udemy");
if (!courseEl) throw new Error("Must be on a Udemy course page!");
const id = courseEl.dataset.clpCourseId;
if (!id) {
// for active course
const secondaryId = document.querySelector("#udemy > div.main-content-wrapper > div.main-content > div").dataset.moduleArgs;
if (!secondaryId || !secondaryId.includes("courseId")) throw new Error("Couldn't get the course ID, make sure you're on the Udemy course page.");
return JSON.parse(secondaryId).courseId;
}
return id;
}
fetch(`https://www.udemy.com/api-2.0/courses/${getCourseId()}/?fields[course]=created,last_update_date,published_time`)
.then(res => res.json())
.then(course => {
console.log(course);
console.info(`This course was created at ${(new Date(course.created)).toLocaleString()}, published at ${(new Date(course.published_time)).toLocaleString()}, and last updated on ${(new Date(course.last_update_date)).toLocaleString()}`);
});
@CodeDraken
Copy link
Author

Basically, it just fetches the dates and prints the JSON and a pretty message in the console. I'll list the steps below to use it:

  1. Go to a course page on Udemy (this can be the overview page or on a lecture)
  2. Open the console for your web browser: Press F12 or CTRL + Shift + I or CMD + Shift + I or navigate the UI menus for the developer tools / console.
  3. Paste the script in and run it.
  4. Optionally, for Chrome browsers, save it to your snippets.

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