Show course name - Canvas Instructure

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

当前为 2024-06-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Show course name - Canvas Instructure
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      5
// @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
    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.match(newDocument.title) ? document.querySelectorAll('span.ellipsible')[1].innerText += ' ' + newDocument.title : document.querySelectorAll('span.ellipsible')[1].innerText = newDocument.title; //Add the full course title after the course code
    document.querySelectorAll('span.ellipsible')[1].title = document.querySelectorAll('span.ellipsible')[1].innerText; //Show the full course title and course code on mouse hover
    setTimeout( () => { document.querySelectorAll('span.ellipsible')[1].style.maxWidth = 'unset' }, 1500); //Set CSS max-width property for proper formatting
  } //Finishes the if condition
})();