Skip to content

Instantly share code, notes, and snippets.

@Scoder12
Created May 13, 2024 23:44
Show Gist options
  • Save Scoder12/0a00bb76fa450e0d1b0ecb40f14badd4 to your computer and use it in GitHub Desktop.
Save Scoder12/0a00bb76fa450e0d1b0ecb40f14badd4 to your computer and use it in GitHub Desktop.
Canvas Cengage WebAssign open in same tab userscript

If you can sign into webassign by opening a canvas assignment and clicking a button like this: open webassign button

then this userscript will make that button open in the same tab instead of in a new window.

How to use:

  1. Install tampermonkey
  2. Click on it's icon > Create New Script
  3. Paste contents of userscript.js
  4. Change the @match line of the script to start with your canvas instance's URL
// ==UserScript==
// @name Cengage Same Tab
// @namespace http://spencerpogo.com/
// @version 2024-05-13
// @description make canvas-authenticated cengage open in the same tab instead of a new one
// @author Spencer Pogorzelski
// @match https://your.canvasinstance/courses/*/assignments/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=webassign.net
// @grant none
// @run-at document-idle
// ==/UserScript==
(function () {
"use strict";
const elts = Array.from(
document.querySelectorAll(
"form[data-tool-launch-type='window'][data-tool-id='gateway.cengage.com']"
)
);
/**
* @argument {MutationRecord[]} mutationList
*/
const callback = (mutationList) => {
for (const mutation of mutationList) {
if (mutation.type !== "attributes") continue;
if (mutation.attributeName !== "target") continue;
if (mutation.target.target !== "_top") {
mutation.target.target = "_top";
}
}
};
const observer = new MutationObserver(callback);
elts.forEach((elt) =>
observer.observe(elt, { attributes: true, attributeFilter: ["target"] })
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment