Show course name - Canvas Instructure

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

当前为 2022-04-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show course name - Canvas Instructure
  3. // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
  4. // @version 3
  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 += ' ' + 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. document.querySelectorAll('span.ellipsible')[1].id = 'Modify'; //Give an unique id to the element
  22. document.head.insertAdjacentHTML('beforeend', '<style>#Modify {max-width: 100px !important;}</style>'); //Set css max width property again for proper formatting
  23. } //Finishes the if condition
  24. })();