-
Notifications
You must be signed in to change notification settings - Fork 42
Initialization Process
One big actor in this process is calculator_desktop-[hash].js, which defines a bunch of AMD modules then requires the module toplevel/calculator_desktop. DesModder patches some of the code to change up some internals, but it can only do this by running some JavaScript code before toplevel/calculator_desktop runs. The loading order of script tags is complicated, but TL;DR it's hard to get code to run before the main calculator_desktop-[hash].js.
The current approach that DesModder takes is:
- Completely block
calculator_desktop-[hash].jsfrom loading (using extension APIs often used for ad blocking). - Run the code that needs to run before
toplevel/calculator_desktop. - Load the main Desmos code (
calculator_desktop-[hash].js). - Load the main DesModder code.
(I say current approach because an alternative is in the works, but it does not work on Firefox, and probably does not work as of the January 9th incremental Desmos update).
A lower-level description of what DesModder does is as follows:
-
Block
calculator_desktop-[hash].js(seenet_request_rules.mdfor more info) -
Content script
preloadContent.js(compiled fromsrc/preload/content.ts) runs on document_start. Its primary purpose is to injectpreloadScript.jsinto the page -
preloadScript.js(compiled fromsrc/preload/script.ts) does many things in order:a. Override
window.ALMOND_OVERRIDESto replace Desmos' Almond AMD loader with a custom loader that overrides some modules.b. Obtain the URL of
calculator_desktop-[hash].js, and insert this content into the page via a script element.c. Once the main JS loads, call
runDesModder. -
The sole purpose of
runDesModderinsidepreloadScript.jsis to load the rest of the DesModder code. It sends the messageget-script-urlto the content script, which sends back the extension-prefixed url that points toscript.js. This is then inserted as a script element, soscript.jsruns. -
script.js(compiled fromsrc/script.ts) is the main DesModder code. It loads all the features of DesModder. Done!