mycourses-utils

Quality of life improvements for RIT MyCourses

目前為 2023-11-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         mycourses-utils
// @namespace    Monkey Scripts
// @description  Quality of life improvements for RIT MyCourses
// @author       Ethan Logue
// @version      1.1
// @match        https://mycourses.rit.edu/*
// @exclude      https://mycourses.rit.edu/d2l/lms/dropbox/*
// @icon         https://mycourses.rit.edu/d2l/lp/web/faviconView?variant=0&version=1
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // custom css rules
    var style = document.createElement('style');
    style.innerHTML = `
        /* container holding the original content */
        .d2l-datalist-item-content > div {
            padding-top: 8px !important;
        }

        /* link tag holding the span */
        .d2l-datalist-item-actioncontrol {
            padding: 0 10px !important;
            margin-left: 1rem !important;
            color: var(--d2l-color-celestine) !important;
        }

        /* hover state of the link tag */
        .d2l-datalist-item-actioncontrol:hover {
            color: var(--d2l-color-celestine-minus-1) !important;
            text-decoration: underline !important;
        }

        /* span tag withing the link thats usually hidden */
        .d2l-offscreen {
            position: relative !important;
            left: 0 !important;
        }
    `;

    document.head.appendChild(style);

    // sidebar events seem to load asynchronously so this gives it a second to load 
    // and tries 10 times to ensure slow connections can still be handled
    window.onload = function() {
        var maxAttempts = 10;
        var attempts = 0;
        var intervalTime = 1000;

        var interval = setInterval(function() {
            attempts++;
            console.log('Checking for element: ' + attempts);

            // gets the span tag that holds the text for the event
            var viewEvents = document.querySelectorAll('span.d2l-offscreen');
            if (viewEvents.length > 0) {
                clearInterval(interval); // clear the interval once the element is found (currently doesn't clear it for some reason)
                viewEvents.forEach(function(event) {
                    event.textContent = 'Open in New Tab';
                    event.parentElement.target = '_blank';
                });
            } else if (attempts >= maxAttempts) {
                console.log('Element not found after ' + attempts + ' attempts.');
                clearInterval(interval); // stops checking when maximum attempts reached
            }
        }, intervalTime);
    }

})();