mycourses-utils

Quality of life improvements for RIT MyCourses

当前为 2023-12-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mycourses-utils
  3. // @namespace Monkey Scripts
  4. // @description Quality of life improvements for RIT MyCourses
  5. // @author Ethan Logue
  6. // @version 1.1
  7. // @match https://mycourses.rit.edu/d2l/home
  8. // @match https://mycourses.rit.edu/d2l/home/*
  9. // @exclude https://mycourses.rit.edu/d2l/lms/dropbox/*
  10. // @icon https://mycourses.rit.edu/d2l/lp/web/faviconView?variant=0&version=1
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // custom css rules
  18. var style = document.createElement('style');
  19. style.innerHTML = `
  20. /* container holding the original content */
  21. .d2l-datalist-item-content > div {
  22. padding-top: 8px !important;
  23. }
  24.  
  25. /* link tag holding the span */
  26. .d2l-datalist-item-actioncontrol {
  27. padding: 0 10px !important;
  28. margin-left: 1rem !important;
  29. color: var(--d2l-color-celestine) !important;
  30. }
  31.  
  32. /* hover state of the link tag */
  33. .d2l-datalist-item-actioncontrol:hover {
  34. color: var(--d2l-color-celestine-minus-1) !important;
  35. text-decoration: underline !important;
  36. }
  37.  
  38. /* span tag withing the link thats usually hidden */
  39. .d2l-offscreen {
  40. position: relative !important;
  41. left: 0 !important;
  42. }
  43. `;
  44.  
  45. document.head.appendChild(style);
  46.  
  47. // sidebar events seem to load asynchronously so this gives it a second to load
  48. // and tries 10 times to ensure slow connections can still be handled
  49. window.onload = function() {
  50. var maxAttempts = 10;
  51. var attempts = 0;
  52. var intervalTime = 1000;
  53.  
  54. var interval = setInterval(function() {
  55. attempts++;
  56. console.log('Checking for element: ' + attempts);
  57.  
  58. // gets the span tag that holds the text for the event
  59. var viewEvents = document.querySelectorAll('span.d2l-offscreen');
  60. if (viewEvents.length > 0) {
  61. clearInterval(interval); // clear the interval once the element is found (currently doesn't clear it for some reason)
  62. viewEvents.forEach(function(event) {
  63. event.textContent = 'Open in New Tab';
  64. event.parentElement.target = '_blank';
  65. });
  66. } else if (attempts >= maxAttempts) {
  67. console.log('Element not found after ' + attempts + ' attempts.');
  68. clearInterval(interval); // stops checking when maximum attempts reached
  69. }
  70. }, intervalTime);
  71. }
  72.  
  73. })();