-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-chrome.js
140 lines (132 loc) · 4.41 KB
/
content-chrome.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
browser.runtime.onMessage.addListener(request => {
debug_log_calc_v = "";
try {
forecast = request.forecast;
temperature = request.temperature;
collision = request.collision ? COLLISION_WIN : COLLISION_LOSE;
default_school = "sunny"; // or sunny
spectators_percent = request.spectators; // -1 is away
defense_type_result = request.defense ? DEFENSE_WIN : DEFENSE_LOOSE;
csv_save = request.gencsv;
window.calc_args = {
forecast: forecast,
temperature: temperature,
collision: collision,
default_school: default_school,
spectators_percent: spectators_percent,
defense_type_result: defense_type_result,
csv_save: csv_save,
};
window.postMessage({ type: "FROM_SCRIPT" }, "*");
} catch(e) {
debug_log_calc(e);
browser.runtime.sendMessage(debug_log_calc_v);
}
});
window.addEventListener("message", function(event) {
try{
//We only accept messages from ourselves
if (event.source != window)
return;
if (event.data.type && (event.data.type == "FROM_PAGE")) {
window.wrappedJSObject = event.data;
calc_strength().then(response => {
browser.runtime.sendMessage(response);
});
}
} catch(e) {
debug_log_calc("Failed to send response to sidebar");
debug_log_calc(e);
browser.runtime.sendMessage(debug_log_calc_v);
}
}, false);
;(function() {
function script() {
// Code injected to web page context which sends to content script data
window.addEventListener("message", function(event) {
// We only accept messages from ourselves
if (event.source != window)
return;
if (event.data.type && (event.data.type == "FROM_SCRIPT")) {
var _obj_pos = Array.apply(null, Array(obj_pos.length));
for (var i = 0; i < obj_pos.length; i++) {
if (obj_pos[i]) {
_obj_pos[i] = {
"options": Array.apply(null, Array(obj_pos[i].options.length))
};
for (var j = 0; j < obj_pos[i].options.length; j++) {
_obj_pos[i].options[j] = {
"value": obj_pos[i].options[j].value,
"className": obj_pos[i].options[j].className,
};
}
}
}
var msg = {
"type": "FROM_PAGE",
"combo_plr": combo_plr,
"plr_cm": plr_cm,
"plr_cd": plr_cd,
"plr_cf": plr_cf,
"plr_st": plr_st,
"plr_fr": plr_fr,
"plr_ld": plr_ld,
"plr_lb": plr_lb,
"plr_rd": plr_rd,
"plr_rb": plr_rb,
"plr_lm": plr_lm,
"plr_rm": plr_rm,
"plr_dm": plr_dm,
"plr_am": plr_am,
"plr_lw": plr_lw,
"plr_rw": plr_rw,
"plr_lf": plr_lf,
"plr_rf": plr_rf,
"plr_sw": plr_sw,
"plr_sf": plr_sf,
"order_pos": order_pos,
"plr_sp1_core": plr_sp1_core,
"plr_sp2_core": plr_sp2_core,
"plr_sp3_core": plr_sp3_core,
"plr_sp4_core": plr_sp4_core,
"plr_sp1_level": plr_sp1_level,
"plr_sp2_level": plr_sp2_level,
"plr_sp3_level": plr_sp3_level,
"plr_sp4_level": plr_sp4_level,
"style_index": style_index,
"pos_bonuses": pos_bonuses,
"super_bonus": super_bonus,
"rest_bonus": rest_bonus,
"plr_id": plr_id,
"plr_styles": plr_styles,
"plr_nat": plr_nat,
"plr_str": plr_str,
"plr_styles": plr_styles,
"plr_names": plr_names,
"plrdat": plrdat,
"curr": curr,
"numOfRows": numOfRows,
// array of selects
"obj_pos": _obj_pos,
// value
"obj_captain": { "value": obj_captain.value },
"obj_morale": { "value": obj_morale.value },
"obj_gamestyle": { "value": obj_gamestyle.value },
// innerText
"obj_syb": { "innerText": obj_syb.innerText },
"obj_kibonus": { "innerText": obj_kibonus.innerText },
"obj_DLB": { "innerText": obj_DLB.innerText },
"obj_MLB": { "innerText": obj_MLB.innerText },
"obj_FLB": { "innerText": obj_FLB.innerText },
};
window.postMessage(msg, "*");
}
}, false);
}
function inject(fn) {
const script = document.createElement('script')
script.text = `(${fn.toString()})();`
document.documentElement.appendChild(script)
}
inject(script)
})()