CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
ProdigyPNP

CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.

GitHub Repository: ProdigyPNP/ProdigyMathGameHacking
Path: blob/master/PHEx/firefox/background.js
Views: 720
1
/**
2
* background.js
3
*
4
* modified by gemsvidø for firefox support
5
*/
6
7
8
9
/** CSP and X-Frame headers */
10
const HEADERS_TO_STRIP_LOWERCASE = [
11
"content-security-policy",
12
"x-frame-options",
13
];
14
15
// Remove CSP and X-Frame headers on all Prodigy domains
16
browser.webRequest.onHeadersReceived.addListener(
17
details => ({
18
responseHeaders: details.responseHeaders.filter(header => !HEADERS_TO_STRIP_LOWERCASE.includes(header.name.toLowerCase()))
19
}),
20
{ urls: ["*://*.prodigygame.com/*"] },
21
["blocking", "responseHeaders"]
22
);
23
24
25
26
27
28
29
/** Set a value in the local storage */
30
function set(key, value) {
31
browser.storage.local.set({ [key]: value });
32
};
33
34
/** Get a value from the local storage */
35
function get(key) {
36
return new Promise(resolve => {
37
browser.storage.local.get([key], result => {
38
resolve(result[key]);
39
})
40
})
41
};
42
43
44
45
// Redirect Requests
46
browser.webRequest.onBeforeRequest.addListener(async details => {
47
48
/** Custom P-NP URL */
49
const url = await get("url");
50
51
/** Use custom URL */
52
const checked = await get("checked");
53
54
/** P-NP URL to be used */
55
const redirectorDomain = (url && checked) ? url : await (await fetch("https://infinitezero.net/domain")).text();
56
57
58
// If hacks are offline, show an alert
59
if (details.url.startsWith("https://code.prodigygame.com/code/") && details.url.includes("/game.min.js")) {
60
fetch("https://raw.githubusercontent.com/ProdigyPNP/ProdigyMathGameHacking/master/PHEx/status.json").then(response => response.json()).then(async data => {
61
if (data.offline == true) {
62
63
if (swal) {
64
swal.fire({
65
title: "Oh no!",
66
html: `Our hacks are currently having some issues, and we're working on it.`,
67
icon: "error"
68
});
69
} else {
70
const res = confirm(`Uh Oh! Hacks look to be down. Hit OK to go to our discord to get updates on when they'll go back up!`);
71
if (res) location = "https://dsc.gg/ProdigyPNP";
72
}
73
}
74
});
75
76
// Block game.min.js
77
browser.webRequest.onBeforeRequest.addListener(
78
_ => ({ cancel: true }),
79
{ urls: ["*://code.prodigygame.com/code/*"] },
80
["blocking"],
81
);
82
83
// see disableIntegrity.js, we append the new game.min to the document
84
return { cancel: true };
85
86
// Public gamemin
87
} else if (details.url.startsWith("https://code.prodigygame.com/js/public-game")) {
88
89
90
const hash = new String(details.url.split("public-game-")[1].split(".")[0]).valueOf();
91
console.log("Public gamemin hash: " + hash)
92
93
// add a redirectUrl header which should redirect public gamemin to our hacked public gamemin.
94
return {
95
redirectUrl: `${redirectorDomain}/public-game.min.js?hash=${hash}&updated=${Date.now()}`
96
};
97
}
98
99
100
}, {
101
102
// Block gamemin and public gamemin
103
urls: [
104
"*://code.prodigygame.com/code/*/game.min.js*",
105
"*://code.prodigygame.com/js/public-game-*.min.js*"
106
],
107
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"],
108
}, ["blocking"]);
109