mycourses-utils

Quality of life improvements for RIT MyCourses

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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/d2l/home
// @match        https://mycourses.rit.edu/d2l/home/*
// @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);
    }

})();