CourseraUXEnhancer

Make Coursera better! Enlarge reading material font size; enforce Space key & ArrowLeft key & ArrowRight key work properly when playing video.

  1. // ==UserScript==
  2. // @name CourseraUXEnhancer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Make Coursera better! Enlarge reading material font size; enforce Space key & ArrowLeft key & ArrowRight key work properly when playing video.
  6. // @author Winston Shu
  7. // @match *://*.coursera.org/learn/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. "use strict";
  14.  
  15. const observer = new MutationObserver(() => {
  16. let previousUrl = "";
  17. let root = document.querySelector("html");
  18.  
  19. if (location.href !== previousUrl) {
  20. previousUrl = location.href;
  21.  
  22. if (
  23. location.href.includes("/supplement/") ||
  24. location.href.includes("/gradedLti") ||
  25. location.href.includes("/ungradedLti") ||
  26. location.href.includes("/discussionPrompt")
  27. ) {
  28. root.style.fontSize = "23px";
  29. } else {
  30. injectSpaceKey();
  31. root.style.fontSize = "16px";
  32. }
  33. }
  34. });
  35. const config = { subtree: true, childList: true };
  36. observer.observe(document, config);
  37.  
  38. function injectSpaceKey() {
  39. window.onload = () => {
  40. window.addEventListener("keydown", (key) => {
  41. let media = document.querySelector("video");
  42.  
  43. if (key.code == "Space") {
  44. media.paused || media.currentTime == 0 ? media.play() : media.pause();
  45. } else if (key.code == "ArrowLeft") {
  46. media.currentTime >= 5
  47. ? (media.currentTime -= 5)
  48. : (media.currentTime = 0);
  49. } else if (key.code == "ArrowRight") {
  50. media.currentTime <= media.duration - 5
  51. ? (media.currentTime += 5)
  52. : (media.currentTime = media.currentTime);
  53. }
  54. });
  55. };
  56. }
  57. })();