-
Notifications
You must be signed in to change notification settings - Fork 60
/
index.html
310 lines (280 loc) · 14.1 KB
/
index.html
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Get Mi Home devices token</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" />
</head>
<body style="background: white">
<div class="container" id="app" style="margin-top: 5rem">
<div class="progress" style="display: none">
<div class="indeterminate"></div>
</div>
<div id="loginPage">
<div class="card-panel red lighten-1" id="message" style="display: none"><h6>Message</h6></div>
<form>
<div>
<label>Enter Mi Home login</label>
<input type="text" id="login" autofocus />
</div>
<div>
<label>Enter Mi Home password</label>
<input type="password" id="password" autofocus />
</div>
<div class="input-field col s12" style="margin-top: 20px">
<select id="serversList">
<option value="cn" selected>China</option>
<option value="ru">Russia</option>
<option value="us">USA</option>
<option value="tw">Taiwan</option>
<option value="sg">Singapore</option>
<option value="de">Germany</option>
</select>
<label>Servers</label>
</div>
<button class="waves-effect waves-light btn" type="submit" id="signButton">Sign in</button>
</form>
</div>
<div id="devicesPage" style="display: none" class="row">
<div style="display: flex; flex-direction: column; margin: 10px">
<button class="waves-effect waves-light btn" id="refreshButton">Refresh devices list</button>
</div>
<div id="devicesList" class="devicesList col s12 m12 l12 xl12"></div>
</div>
<div id="setVacuumVoicePack" class="modal">
<div class="modal-content" style="height: 500px">
<h4>Modal Header</h4>
<div class="input-field col s12" style="padding-top: 10px">
<select id="setVacuumVoicePackSelect">
<option value="" disabled selected>Choose voice</option>
<option value="5021">озвучка Винни Пух</option>
<option value="5022">озвучка Домовенок Кузя + Алиса</option>
<option value="5023">озвучка ельцин</option>
<option value="5024">озвучка Алиса</option>
<option value="5025">озвучка Робот Бендер + Алиса</option>
<option value="5026">озвучка Starcraft_2</option>
<option value="5027">озвучка WarCraft_II</option>
<option value="5028">озвучка Максим</option>
<option value="5029">озвучка женский голос</option>
<option value="5030">озвучка Татьяна</option>
<option value="5031">озвучка Максим 1</option>
<option value="5032">озвучка Максим 2</option>
<option value="5033">озвучка Максим 3</option>
<option value="5034">озвучка Максим мат 1</option>
<option value="5035">озвучка Максим мат 2</option>
<option value="5036">озвучка Максим мат 3</option>
<option value="5037">озвучка Советские фильмы</option>
<option value="5038">озвучка Советские фильмы 2</option>
<option value="5039">озвучка google_voice</option>
<option value="5040">озвучка кожанные ублюдки 2</option>
<option value="5041">озвучка Максим мат_3</option>
<option value="5042">озвучка Филипп</option>
<option value="5043">озвучка Кожаные ублюдки</option>
<option value="5044">озвучка Кузя+Захар</option>
<option value="5045">озвучка Вини пух 2</option>
<option value="5046">озвучка Вини пух 3</option>
<option value="5047">озвучка Захар</option>
<option value="5048">озвучка R2D2_RU</option>
</select>
<label>Voice packs</label>
</div>
</div>
<div class="modal-footer">
<a data-id="installVacuumVoicePack" class="waves-effect waves-green btn-flat">Install</a>
</div>
</div>
</div>
</body>
<script>
const electron = require("electron");
const { ipcRenderer } = electron;
const devicesList = document.querySelector(".devicesList");
let ip, token;
ipcRenderer.on("devices", function (e, result) {
const devicesPage = document.querySelector("#devicesPage");
const message = document.querySelector("#message");
const loading = document.querySelector(".progress");
devicesList.innerHTML = "";
if (result && result.message) {
const login = document.querySelector("#login");
const password = document.querySelector("#password");
const signButton = document.querySelector("#signButton");
login.disabled = false;
password.disabled = false;
signButton.disabled = false;
loading.style.display = "none";
message.style = "";
message.innerHTML = result.message;
} else {
loading.style.display = "none";
const form = document.querySelector("#loginPage");
devicesPage.style = "";
form.style.display = "none";
const devices = result.filter((device) => device.parent_model == "");
let gatewayWithChildDevices = {};
const gateways = [...new Set(result.filter((device) => device.parent_model != "").map((item) => item.parent_model))];
gateways.forEach((gateway) => {
gatewayWithChildDevices[gateway] = result.filter((device) => device.parent_model == gateway);
});
devices.forEach((device) => {
const div = document.createElement("div");
div.className = "card horizontal";
div.style = "border-radius: 1rem";
div.id = device.did;
if (gatewayWithChildDevices.hasOwnProperty(device.model)) {
if (!!gatewayWithChildDevices[device.model].filter((g) => g.parent_id == device.did).length) {
div.insertAdjacentHTML(
"beforeend",
` <div class="card-image" style="display: flex; flex-direction: column; justify-content: center;">
<img src="${device.deviceImage}" width="168" height="168" style="object-fit: cover; ${device.isOnline ? "opacity: 1" : "opacity: 0.4"}">
</div>
<div class="card-stacked">
<div class="card-content">
<span class="card-title" style="color: #000">${device.name}</span>
<p>IP: ${device.localip}</p>
<p>Token: ${device.token}</p>
<p>MAC: ${device.mac}</p>
<p>Model: ${device.model}</p>
<p>Region: ${device.region}</p>
<p>Child devices count: ${gatewayWithChildDevices[device.model].filter((g) => g.parent_id == device.did).length}</p>
</div>
</div>
`
);
}
} else {
div.insertAdjacentHTML(
"beforeend",
` <div class="card-image" style="display: flex; flex-direction: column; justify-content: center;">
<img src="${device.deviceImage}" width="168" height="168" style="object-fit: cover; ${device.isOnline ? "opacity: 1" : "opacity: 0.4"}">
</div>
<div class="card-stacked">
<div class="card-content">
<span class="card-title" style="color: #000">${device.name}</span>
<p>IP: ${device.localip}</p>
<p>Token: ${device.token}</p>
<p>MAC: ${device.mac}</p>
<p>Model: ${device.model}</p>
<p>Region: ${device.region}</p>
</div>
</div>
`
);
}
if (device.model == "dreame.vacuum.mc1808") {
const footerAction = document.createElement("div");
footerAction.className = "card-action";
footerAction.insertAdjacentHTML(
"beforeend",
`<a class="waves-effect waves-light btn" data-vacuumDeviceSetVoicePack='true' data-ip=${device.localip} data-token=${device.token}>Install voice pack</a><a style="margin-left: 10px" class="waves-effect waves-light btn" data-vacuumDevicePlayVoice='true' data-ip=${device.localip} data-token=${device.token}>Play sound</a>`
);
let cardStacked = null;
for (var i = 0; i < div.childNodes.length; i++) {
if (div.childNodes[i].className == "card-stacked") {
cardStacked = div.childNodes[i];
break;
}
}
cardStacked.appendChild(footerAction);
}
devicesList.appendChild(div);
});
}
});
ipcRenderer.on("vacuumVoicePackSuccessfullyInstalled", function (e, result) {
if (result && result.message) {
} else {
let modalElem = document.querySelector("#setVacuumVoicePack");
let modalInstance = M.Modal.getInstance(modalElem);
modalInstance.close();
}
});
document.body.addEventListener("click", (e) => {
let modalElem = document.querySelector("#setVacuumVoicePack");
let modalInstance = M.Modal.getInstance(modalElem);
let selectElem = document.querySelector("#setVacuumVoicePackSelect");
let selectInstance = M.FormSelect.getInstance(selectElem);
if (e.target.dataset.vacuumdevicesetvoicepack) {
modalInstance.open();
ip = e.target.dataset.ip;
token = e.target.dataset.token;
}
if (e.target.dataset.vacuumdeviceplayvoice) {
ip = e.target.dataset.ip;
token = e.target.dataset.token;
ipcRenderer.send("playVoice", {
ip,
token,
});
}
if (e.target.id == "refreshButton") {
const login = document.querySelector("#login");
const password = document.querySelector("#password");
const server = document.getElementById("serversList").M_FormSelect.input.value;
ipcRenderer.send("getDevices", { login: login.value, password: password.value, server });
}
if (e.target.dataset.id == "installVacuumVoicePack") {
const voices = [
{ name: "озвучка Винни Пух", sa_id: 5021 },
{ name: "озвучка Домовенок Кузя + Алиса", sa_id: 5022 },
{ name: "озвучка ельцин", sa_id: 5023 },
{ name: "озвучка Алиса", sa_id: 5024 },
{ name: "озвучка Робот Бендер + Алиса", sa_id: 5025 },
{ name: "озвучка Starcraft_2", sa_id: 5026 },
{ name: "озвучка WarCraft_II", sa_id: 5027 },
{ name: "озвучка Максим", sa_id: 5028 },
{ name: "озвучка женский голос", sa_id: 5029 },
{ name: "озвучка Татьяна", sa_id: 5030 },
{ name: "озвучка Максим 1", sa_id: 5031 },
{ name: "озвучка Максим 2", sa_id: 5032 },
{ name: "озвучка Максим 3", sa_id: 5033 },
{ name: "озвучка Максим мат 1", sa_id: 5034 },
{ name: "озвучка Максим мат 2", sa_id: 5035 },
{ name: "озвучка Максим мат 3", sa_id: 5036 },
{ name: "озвучка Советские фильмы", sa_id: 5037 },
{ name: "озвучка Советские фильмы 2", sa_id: 5038 },
{ name: "озвучка google_voice", sa_id: 5039 },
{ name: "озвучка кожанные ублюдки 2", sa_id: 5040 },
{ name: "озвучка Максим мат_3", sa_id: 5041 },
{ name: "озвучка Филипп", sa_id: 5042 },
{ name: "озвучка Кожаные ублюдки", sa_id: 5043 },
{ name: "озвучка Кузя+Захар", sa_id: 5044 },
{ name: "озвучка Вини пух 2", sa_id: 5045 },
{ name: "озвучка Вини пух 3", sa_id: 5046 },
{ name: "озвучка Захар", sa_id: 5047 },
{ name: "озвучка R2D2_RU", sa_id: 5048 },
];
ipcRenderer.send("setVacuumVoicePack", {
ip,
token,
packID: voices.filter((v) => v.name == document.getElementById("setVacuumVoicePackSelect").M_FormSelect.input.value)[0].sa_id,
});
}
});
document.addEventListener("DOMContentLoaded", () => {
let modalElems = document.querySelector(".modal");
let modalInstances = M.Modal.init(modalElems, { dismissible: false });
let selectElems = document.querySelectorAll("select");
let selectInstances = M.FormSelect.init(selectElems);
});
document.querySelector("form").addEventListener("submit", submitForm);
function submitForm(e) {
e.preventDefault();
const loading = document.querySelector(".progress");
const message = document.querySelector("#message");
message.innerHTML = "";
message.style.display = "none";
loading.style = "";
const login = document.querySelector("#login");
const password = document.querySelector("#password");
const signButton = document.querySelector("#signButton");
const server = document.getElementById("serversList").M_FormSelect.input.value;
login.disabled = true;
password.disabled = true;
signButton.disabled = true;
ipcRenderer.send("getDevices", { login: login.value, password: password.value, server });
}
</script>
<script type="text/javascript" src="assets/materialize.min.js"></script>
</html>