-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
88 lines (72 loc) · 2.72 KB
/
main.js
File metadata and controls
88 lines (72 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
let injected = false;
// Causes some errors sometimes
// patchCleverTricks();
browser.runtime.onMessage.addListener(function (data) {
if (data === "init") tryInit();
});
document.addEventListener("error", function (event) {
alert(`${event.error} @ ${event.filename}:${event.lineno}`);
});
function patchCleverTricks() {
// Some developers are sneaky and try to prevent editing of
// certain variables. That hurts my feelings!
//
// A downside of this is that it might break stuff other stuff on random websites, since it needs to inject fast. Oops.
let _defineProperty = window.wrappedJSObject.Object.defineProperty;
function _new_DefProp(obj, prop, descriptor) {
// if (descriptor.configurable === false) {
// console.log(prop, "doesnt want to configure!");
// descriptor.configurable = true;
// }
if (descriptor.writable === false) {
console.log(prop, "doesnt want to write!");
descriptor.writable = true;
}
return _defineProperty(obj, prop, descriptor);
}
exportFunction(_new_DefProp, window, { defineAs: "SA_NEWDEFPROP" });
window.wrappedJSObject.Object.defineProperty =
window.wrappedJSObject.SA_NEWDEFPROP;
}
function getWindowVariables() {
// Genius solution by jungy
// https://stackoverflow.com/a/17246535
// Make a clean slate window--no custom properties
let iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);
// Here's our (tainted) property list
let currentWindow = Object.getOwnPropertyNames(window.wrappedJSObject);
// Filter based on presence in clean slate
let results = currentWindow.filter(function (prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
});
document.body.removeChild(iframe);
return results;
}
async function tryInit() {
// Profile current game engine. If no supported game engine is found, go home.
if (injected) return;
let vars = getWindowVariables();
console.log(vars);
if (window.wrappedJSObject.SugarCube) {
injected = true;
const { initSugarCube } = await import(
browser.runtime.getURL("engines/sugarcube.js")
);
await initSugarCube();
return;
} else if (window.wrappedJSObject.$dataActors) {
const { initRPGMaker } = await import(
browser.runtime.getURL("engines/rpgmaker.js")
);
await initRPGMaker();
} else if (window.wrappedJSObject.Module) {
const { initRenPyWeb } = await import(
browser.runtime.getURL("engines/renpy.js")
);
await initRenPyWeb();
} else {
console.error("Nothing :^(");
}
}