Yet Another Udemy Course Creation Date Getter

Shows the creation date of the course below the latest update date.

  1. // ==UserScript==
  2. // @name Yet Another Udemy Course Creation Date Getter
  3. // @namespace <https://github.com/lundeen-bryan>
  4. // @version 2.0.0
  5. // @description Shows the creation date of the course below the latest update date.
  6. // @author lundeen-bryan based on a script by scriptbug
  7. // @match https://www.udemy.com/course/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=udemy.com
  9. // @grant GM_addStyle
  10. // @license GPL-2.0-or-later
  11. // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  12. // ==/UserScript==
  13.  
  14. var $ = window.$;
  15. var x = document.body.getAttribute("data-clp-course-id");
  16. $.get("https://www.udemy.com/api-2.0/courses/" + x + "/?fields[course]=created", function (data) {
  17. var date = new Date(data.created);
  18. var formattedDate = (date.getMonth() + 1) + "/" + date.getFullYear(); // Adjust the format as needed
  19.  
  20. // Function to create the date element
  21. function createDateElement() {
  22. var creationDateDiv = document.createElement("div");
  23. creationDateDiv.className = "clp-lead__element-item";
  24. creationDateDiv.innerHTML = '<span>Created on ' + formattedDate + '</span>';
  25. return creationDateDiv;
  26. }
  27.  
  28. // Function to insert the creation date
  29. function insertCreationDate() {
  30. var updateDateElement = document.querySelector("[data-purpose='last-update-date']");
  31. if (updateDateElement) {
  32. updateDateElement.parentNode.insertBefore(createDateElement(), updateDateElement.nextSibling);
  33. return true;
  34. }
  35. return false;
  36. }
  37.  
  38. // Try to insert immediately
  39. if (!insertCreationDate()) {
  40. // Use MutationObserver as the first fallback
  41. var observer = new MutationObserver(function (mutations, me) {
  42. if (insertCreationDate()) {
  43. me.disconnect(); // stop observing when done
  44. }
  45. });
  46.  
  47. observer.observe(document, {
  48. childList: true,
  49. subtree: true
  50. });
  51.  
  52. // Additional fallback: try again after a delay
  53. setTimeout(function () {
  54. if (!insertCreationDate()) {
  55. console.error("Could not insert the creation date after delay.");
  56. }
  57. }, 5000); // Wait for 5 seconds as the last resort
  58. }
  59. });