CourseraUXEnhancer

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         CourseraUXEnhancer
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Make Coursera better! Enlarge reading material 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/") ||
        location.href.includes("/gradedLti") ||
        location.href.includes("/ungradedLti") ||
        location.href.includes("/discussionPrompt")
      ) {
        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") {
          media.paused || media.currentTime == 0 ? media.play() : media.pause();
        } 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);
        }
      });
    };
  }
})();