CanvasExtractCourseRoster

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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);

})();