ID: I202606042110
Status: idea
Tags: Tampermonkey, pastebin

brightspace exporter

I created the script below to download all Brightspace folders of a module.

// ==UserScript==
// @name         Brightspace Export Tool
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Batch export from Brightspace
// @author       You
// @match        https://brightspace.avans.nl/*
// @grant        none
// ==/UserScript==
 
(function() {
  'use strict';
 
  let popupCreated = false;
 
  function createPopup() {
    if (popupCreated) return;
 
    const navTree = document.querySelector('.navigation-tree');
    if (!navTree) return;
 
    popupCreated = true;
 
    const popup = document.createElement('div');
    popup.style.cssText = `
      position: fixed;
      top: 10px;
      left: 10px;
      background: white;
      border: 2px solid #333;
      padding: 10px;
      z-index: 10000;
      border-radius: 5px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    `;
 
    const button = document.createElement('button');
    button.textContent = 'Export';
    button.style.cssText = `
      padding: 8px 12px;
      background: #007bff;
      color: white;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      font-weight: bold;
    `;
 
    popup.appendChild(button);
    document.body.appendChild(popup);
 
    button.addEventListener('click', async () => {
      button.disabled = true;
      button.textContent = 'Processing...';
 
      try {
        const items = Array.from(
          navTree.querySelectorAll(':scope > .navigation-item')
        );
 
        if (items.length === 0) {
          alert('Could not find navigation-item elements');
          return;
        }
 
        for (let i = 0; i < items.length; i++) {
          items[i].click();
          await new Promise(r => setTimeout(r, 1000));
 
          const header = document.getElementById('content-header');
          if (!header) {
            alert('Could not find content-header element');
            return;
          }
 
          const tray = header.querySelector('.header-button-tray');
          if (!tray) {
            alert('Could not find header-button-tray element');
            return;
          }
 
          const downloadBtn = tray.querySelector(
            '.download-content-button'
          );
          if (downloadBtn) {
            downloadBtn.click();
          }
 
          if (i < items.length - 1) {
            await new Promise(r => setTimeout(r, 5000));
          }
        }
 
        await new Promise(r => setTimeout(r, 5000));
        alert('Export completed!');
      } catch (error) {
        alert('Error: ' + error.message);
      } finally {
        button.disabled = false;
        button.textContent = 'Export';
      }
    });
  }
 
  window.addEventListener('load', () => {
    setTimeout(createPopup, 5000);
    setInterval(createPopup, 10000);
  });
})();

References