Greasy Fork 还支持 简体中文。

CanvasExtractCourseRoster

A nice GUI way to extract users+emails from a Canvas course in a simple-to-use format.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         CanvasExtractCourseRoster
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  A nice GUI way to extract users+emails from a Canvas course in a simple-to-use format.
// @author       Jason Hemann
// @match        *://*.instructure.com/courses/*/users
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract names and emails
    function extractNamesAndEmails() {
        // Combined check for tab-0 div and table
        let table = document.getElementById('tab-0')?.querySelector('div > div:nth-of-type(2) > table');
        if (!table) {
            alert('Table not found in the expected location.');
            return;
        }

        // Get all rows in the table
        let rows = table.querySelectorAll('tbody > tr');
        let results = [];

        // Extract names and emails from each row
        for (let row of rows) {
            let nameCell = row.querySelector('td:nth-of-type(2) > a');
            let emailCell = row.querySelector('td:nth-of-type(3)');

            if (!(nameCell && emailCell)) {
                alert('Table is malformed.');
                return; // Stop the function if a row is malformed
            }

            let name = nameCell.textContent.trim();
            let email = emailCell.textContent.trim();
            results.push(`${name}\t${email}`);
        }

        // Copy the results to the clipboard
        GM_setClipboard(results.join('\n'));
    }

    // Create a button and style it
    let button = document.createElement('button');
    button.innerHTML = 'Extract Names and Emails';
    button.style.position = 'fixed';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = '1000';
    button.style.padding = '10px';
    button.style.backgroundColor = '#28a745';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';

    // Add the button to the page
    document.body.appendChild(button);

    // Add click event listener to the button
    button.addEventListener('click', extractNamesAndEmails);

})();