Skip to content

Commit

Permalink
faster-project-loading: Fix dropping code into sprite-pane (ScratchAd…
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldLanguages authored Feb 15, 2024
1 parent aff0e7c commit aa12349
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addons/faster-project-loading/userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ export default async function ({ addon }) {
const BACKPACK_URL = "https://backpack.scratch.mit.edu/";
// Inserting sprites from the backpack requests a ZIP archive from backpack.scratch.mit.edu, so we want to allow those
const SPRITE_FILE_EXTENSION = ".zip";
// Dropping a code item from the backpack into a specific sprite within the sprite-pane (NOT into the code area)
// requests a JSON file (https://backpack.scratch.mit.edu/{hash}.json) which we shouldn't block
const CODE_FILE_EXTENSION = ".json";

const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, ...moreArgs) {
if (
!addon.self.disabled &&
method === "GET" &&
url.startsWith(BACKPACK_URL) &&
!url.endsWith(SPRITE_FILE_EXTENSION)
!url.endsWith(SPRITE_FILE_EXTENSION) &&
!url.endsWith(CODE_FILE_EXTENSION)
) {
/*
We don't want to block actual requests for backpack assets.
Expand Down

0 comments on commit aa12349

Please sign in to comment.