Greasy Fork

Show course name - Canvas Instructure

Shows the full course name and course code of your class on any page.

目前为 2022-01-13 提交的版本。查看 最新版本

// ==UserScript==
// @name         Show course name - Canvas Instructure
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      0.1
// @description  Shows the full course name and course code of your class on any page.
// @author       hacker09
// @match        https://*.instructure.com/*
// @icon         https://du11hjcvx0uqb.cloudfront.net/br/dist/images/favicon-e10d657a73.ico
// @run-at       document-end
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';
  if (location.pathname.split('/').length > 3) //If the user is not on the Home page of the course
  { //Starts the if condition
    (async () => { //Creates a function to get the course title and Starts the function
      const response = await (await fetch(location.origin + '/courses/' + location.pathname.split('/')[2])).text(); //Fetch
      const newDocument = new DOMParser().parseFromString(response, 'text/html'); //Parses the fetch response
      document.querySelectorAll('span.ellipsible')[1].innerText += ' ' + newDocument.title; //Add the full course title after the course code
    })(); //Finishes the async function
  } //Finishes the if condition
})();