Skip to content

Instantly share code, notes, and snippets.

@Badbird5907
Last active November 20, 2023 02:56
Show Gist options
  • Save Badbird5907/565b94e4f0c9e54e5b9af7d30cd9a1cc to your computer and use it in GitHub Desktop.
Save Badbird5907/565b94e4f0c9e54e5b9af7d30cd9a1cc to your computer and use it in GitHub Desktop.
Brightspace open embedded content in new page (TDSB)
// ==UserScript==
// @name Open IFrame in new page
// @namespace https://badbird.dev/
// @version 0.1
// @description Adds a open in new tab for button for embedded content (PDFs) in brightspace.
// @author Badbird5907
// @match https://tdsb.elearningontario.ca/d2l/ui/apps/smart-curriculum/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=elearningontario.ca
// @grant none
// ==/UserScript==
(function() {
'use strict';
function getIFrame() {
return document.querySelector(".resizing-iframe");
}
function openIframeSource() {
const iframe = getIFrame();
if (iframe) {
const iframeSrc = iframe.getAttribute('src');
window.open(iframeSrc, '_blank');
}
}
let added = false;
function addOpenSourceButton() {
if (added) return;
const downloadButton = document.querySelector('.download-content-button');
if (downloadButton) {
const openSourceButton = document.createElement('d2l-button-icon');
// openSourceButton.classList.add('download-content-button');
openSourceButton.setAttribute('icon', 'tier1:new-window');
openSourceButton.setAttribute('title', 'Open In New Tab');
openSourceButton.setAttribute('aria-label', 'Open');
openSourceButton.setAttribute('type', 'button');
openSourceButton.addEventListener('click', openIframeSource);
downloadButton.parentNode.insertBefore(openSourceButton, downloadButton.nextSibling);
added = true;
}
}
const observer = new MutationObserver(() => {
if (getIFrame()) {
addOpenSourceButton();
}
});
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment