Greasy Fork

CourseraUXEnhancer

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

当前为 2022-11-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         CourseraUXEnhancer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Make Coursera better again! Enlarge supplement reading font size; enforce Space key & ArrowLeft key & ArrowRight key work properly when playing video.
// @author       Winston Shu
// @match        *://*.coursera.org/learn/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
    "use strict";
  
    const observer = new MutationObserver(() => {
      let previousUrl = "";
      let root = document.querySelector("html");
  
      if (location.href !== previousUrl) {
        previousUrl = location.href;
  
        if (location.href.includes("/supplement/")) {
          root.style.fontSize = "23px";
        } else {
          injectSpaceKey();
          root.style.fontSize = "16px";
        }
      }
    });
    const config = { subtree: true, childList: true };
    observer.observe(document, config);
  
    function injectSpaceKey() {
      window.onload = () => {
        window.addEventListener("keydown", (key) => {
          let media = document.querySelector("video");
  
          if (key.code == "Space") {
            console.log(media.paused);
            media.paused || media.currentTime == 0 ? media.play() : media.pause();
            console.log(media.currentTime, media.playbackRate);
          } else if (key.code == "ArrowLeft") {
            media.currentTime >= 5
              ? (media.currentTime -= 5)
              : (media.currentTime = 0);
          } else if (key.code == "ArrowRight") {
            media.currentTime <= media.duration - 5
              ? (media.currentTime += 5)
              : (media.currentTime = media.currentTime);
          }
        });
      };
    }
  })();