CourseraUXEnhancer

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
        }
      });
    };
  }
})();