Skip to content

Instantly share code, notes, and snippets.

@jared-hughes
Created December 14, 2022 08:57
Show Gist options
  • Save jared-hughes/1a075185cdfca1b52b773c6c7f784500 to your computer and use it in GitHub Desktop.
Save jared-hughes/1a075185cdfca1b52b773c6c7f784500 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Expose topLevelComponents
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Expose Desmos's topLevelComponents as window._topLevelComponents. The global window._topLevelComponents is available after Desmos loads. Make sure to run at document-start.
// @author fireflame241
// @match https://www.desmos.com/calculator
// @icon https://www.google.com/s2/favicons?sz=64&domain=desmos.com
// @grant none
// ==/UserScript==
let oldDefine;
function newDefine(moduleName, dependencies, definition) {
if (moduleName === "main/calc_desktop") {
const itlc = window.require("main/instantiate-top-level-components");
const currInstantiate = itlc.default;
itlc.default = function () {
window._topLevelComponents = currInstantiate(...arguments);
return window._topLevelComponents;
};
}
return oldDefine(...arguments);
}
// without this, you get Error: touchtracking missing jquery
newDefine.amd = {
jQuery: true,
};
if (window.ALMOND_OVERRIDES !== undefined) {
window.alert(
"Warning: you have another script installed that overrides modules definitions. " +
"This is incompatible with Expose topLevelComponents" +
"so try disabling other Tampermonkey scripts and DesModder."
);
}
// trick to override `define`s
window.ALMOND_OVERRIDES = new Proxy(
{},
{
get(target, prop, receiver) {
if (prop === "define") {
oldDefine = window.define;
return newDefine;
} else {
return Reflect.get(target, prop, receiver);
}
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment