Last active
July 22, 2021 18:09
-
-
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.
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
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()}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: