Greasy Fork 还支持 简体中文。

UConn Rate My Professor Search

Add a button to get instructor's professor rating from ratemyprof from the UConn catalog

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         UConn Rate My Professor Search
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Add a button to get instructor's professor rating from ratemyprof from the UConn catalog
// @author       Michael Santos
// @match        https://catalog.uconn.edu/course-search/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=uconn.edu
// @grant        GM_xmlhttpRequest
// @grant        GM_openInTab
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to perform the Google search
    function searchInstructor(instructorName) {
        const query = encodeURIComponent(`${instructorName} UCONN Rate my Professor`);
        const url = `https://www.google.com/search?q=${query}`;

        GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            headers: {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.3'
            },
            onload: function(response) {
                // Parse the response to find the Rate My Professor link
                const parser = new DOMParser();
                const doc = parser.parseFromString(response.responseText, 'text/html');
                const links = doc.querySelectorAll('a');

                for (let link of links) {
                    if (link.href.includes('ratemyprofessors.com')) {
                        // Open the Rate My Professor link in a new tab
                        GM_openInTab(link.href, { active: true });
                        return;
                    }
                }

                console.error('Rate My Professor link not found');
            },
            onerror: function(error) {
                console.error('Request failed', error);
            }
        });
    }

    // Function to add a search button next to each instructor name
    function addSearchButtons() {
        const instructorElements = document.querySelectorAll('body > main > div.panel.panel--2x.panel--kind-details.panel--visible > div > div.panel__body > div:nth-child(16) > div > div > div');
        instructorElements.forEach(element => {
            // Check if the button is already added to avoid duplicates
            if (!element.querySelector('.search-rmp-button')) {
                const instructorName = element.innerText;
                const button = document.createElement('button');
                button.innerText = 'Search RMP';
                button.className = 'search-rmp-button';
                button.style.marginLeft = '10px';
                button.addEventListener('click', () => searchInstructor(instructorName));
                element.appendChild(button);
            }
        });
    }

    // Set interval to add search buttons every second
    setInterval(addSearchButtons, 1000);

})();