Show course name - Canvas Instructure

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

  1. // ==UserScript==
  2. // @name Show course name - Canvas Instructure
  3. // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
  4. // @version 5
  5. // @description Shows the full course name and course code of your class on any page.
  6. // @author hacker09
  7. // @match https://*.instructure.com/*
  8. // @icon https://du11hjcvx0uqb.cloudfront.net/br/dist/images/favicon-e10d657a73.ico
  9. // @run-at document-end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15. if (location.pathname.split('/').length > 3) //If the user is not on the Home page of the course
  16. { //Starts the if condition
  17. const response = await (await fetch(location.origin + '/courses/' + location.pathname.split('/')[2])).text(); //Fetch
  18. const newDocument = new DOMParser().parseFromString(response, 'text/html'); //Parses the fetch response
  19. 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
  20. document.querySelectorAll('span.ellipsible')[1].title = document.querySelectorAll('span.ellipsible')[1].innerText; //Show the full course title and course code on mouse hover
  21. setTimeout( () => { document.querySelectorAll('span.ellipsible')[1].style.maxWidth = 'unset' }, 1500); //Set CSS max-width property for proper formatting
  22. } //Finishes the if condition
  23. })();