|
1 | 1 | (async () => {
|
| 2 | + |
| 3 | + /** Get an item from the chrome local storage. */ |
2 | 4 | function get(key) {
|
3 | 5 | return new Promise(resolve => {
|
4 | 6 | chrome.storage.local.get([key], result => {
|
|
7 | 9 | });
|
8 | 10 | }
|
9 | 11 |
|
| 12 | + /** Custom P-NP URL from popup.js */ |
| 13 | + const url = await get("url"); |
10 | 14 |
|
| 15 | + /** Use Custom P-NP URL. */ |
| 16 | + const checked = await get("checked"); |
11 | 17 |
|
12 |
| - if (!window.scriptIsInjected) { |
13 |
| - // get options from local |
14 |
| - const url = await get("url"); |
15 |
| - const checked = await get("checked"); |
16 |
| - const redirectorDomain = (url && checked) ? url : "https://infinitezero.net/eval"; |
17 |
| - |
| 18 | + /** P-NP URL to use. Code: (If url exists and checked is true, then use url. Else, get a domain from infinite zero.) */ |
| 19 | + const redirectorDomain = (url && checked) ? url : (await (await fetch("https://infinitezero.net/domain")).text()).valueOf(); |
18 | 20 |
|
| 21 | + /** The hash for game.min.js */ |
| 22 | + const hash = "sha256-" + (await (await fetch(`${redirectorDomain}/hash?updated=${Date.now()}`)).text()).valueOf(); |
| 23 | + |
19 | 24 |
|
20 |
| - |
21 |
| - window.scriptIsInjected = true; |
| 25 | + if (!window.scriptIsInjected) { |
| 26 | + |
| 27 | + |
| 28 | + var rs4 = new String().valueOf(); |
22 | 29 |
|
23 | 30 | function redirectorCheck() {
|
| 31 | + |
24 | 32 | fetch(`${redirectorDomain}/game.min.js?updated=${Date.now()}`)
|
25 | 33 | .then(res => res.text())
|
26 | 34 | .then(response => {
|
| 35 | + |
| 36 | + rs4 = response; |
27 | 37 | console.log("[PHEx] Connection to server was Successful!");
|
28 | 38 | console.log(redirectorDomain);
|
29 | 39 |
|
30 | 40 | // <script src="https://code.prodigygame.com/code/3-13-0/game.min.js?v=3-13-0" onload="SW.Load.onGameLoad();" crossorigin="anonymous"></script>
|
31 | 41 | // we cancel the real game.min, and just append ours
|
32 | 42 | // a messy solution for sure, but this should only be a bandaid on a bulletwound
|
33 | 43 | const injectedScript = document.createElement("script");
|
34 |
| - injectedScript.innerHTML = response; |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + injectedScript.innerHTML = new String(rs4.valueOf()); |
35 | 48 |
|
36 | 49 | document.body.append(injectedScript);
|
37 | 50 | })
|
38 | 51 | .catch(async (error) => {
|
39 | 52 | // If fetch spits out error, trigger dialog box
|
40 |
| - eval(await (await fetch('https://unpkg.com/sweetalert2')).text()); |
41 | 53 | if (swal) {
|
42 | 54 | swal.fire({
|
43 | 55 | title: "Oh no!",
|
|
50 | 62 | }
|
51 | 63 | });
|
52 | 64 | }
|
| 65 | + |
| 66 | + /** Run the redirectorCheck() function with a 1-second delay. */ |
53 | 67 | setTimeout(redirectorCheck, 1000);
|
54 | 68 |
|
| 69 | + /** User's version of PHEx */ |
55 | 70 | const pluginVersion = chrome.runtime.getManifest().version;
|
| 71 | + |
| 72 | + /** Latest version of PHEx. */ |
56 | 73 | const supportedVersion = (await (await fetch(`${redirectorDomain}/version`)).text());
|
57 |
| - // Checks for plugin version. If outdated, triggers dialog box. |
| 74 | + |
| 75 | + |
| 76 | + /** Checks for plugin version. If outdated, triggers dialog box */ |
58 | 77 | if (pluginVersion !== supportedVersion) {
|
59 |
| - const res = confirm("PHEx is outdated. If you experience any errors, please update."); |
| 78 | + const res = confirm(`PHEx is outdated. If you experience any errors, please update.\n\Your Version: ${pluginVersion}\nLatest Version: ${supportedVersion}`); |
60 | 79 |
|
61 | 80 | if (res) location = "https://github.com/ProdigyPNP/ProdigyMathGameHacking/blob/master/meta/wiki/UPDATING.md";
|
62 | 81 | }
|
63 | 82 |
|
64 |
| - // Disable integrity |
| 83 | + |
| 84 | + /** Remove integrity attributes from scripts and links. */ |
65 | 85 | console.groupCollapsed("[PHEx] integrity patches");
|
66 |
| - [...document.getElementsByTagName("script"), ...document.getElementsByTagName("link")].forEach(v => { |
67 |
| - if (v.integrity) { |
68 |
| - console.log("[PHEx] " + v.integrity); |
69 |
| - v.removeAttribute("integrity"); |
| 86 | + [...document.getElementsByTagName("script"), ...document.getElementsByTagName("link")].forEach(element => { |
| 87 | + if (element.hasAttribute("integrity")) { |
| 88 | + console.log("[PHEx] " + element.getAttribute("integrity")); |
| 89 | + element.removeAttribute("integrity"); |
70 | 90 | }
|
71 | 91 | });
|
72 | 92 | console.groupEnd("[PHEx] integrity patches");
|
| 93 | + /** End disable integrity */ |
| 94 | + |
| 95 | + |
| 96 | + /** Script is now injected. */ |
| 97 | + window.scriptIsInjected = true; |
73 | 98 | }
|
74 | 99 | })();
|
0 commit comments