-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
458 lines (401 loc) · 14 KB
/
main.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// Modules to control application life and create native browser window
const {app, BrowserWindow, session, Menu, shell} = require('electron')
const path = require('path')
const isDev = require("electron-is-dev");
const windowStateKeeper = require('electron-window-state');
const settings = require("electron-settings");
const prompt = require('electron-prompt');
const axios = require('axios');
const fs = require('fs');
const contextMenu = require('electron-context-menu');
//const injected = require('./script_prod.js')
// https://www.twitch.tv/subs/saikomicart
isDarkTheme = true;
var service = 'streamelements'
function createPanel(width, height, url) {
// Create the browser window.
const window = new BrowserWindow({
width: width,
height: height,
parent: chatWindow,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
window.loadURL(url)
return window
}
var chatWindow;
async function createWindow () {
let chatWindowState = windowStateKeeper({
defaultWidth: 380,
defaultHeight: 720
});
// Create the browser window.
chatWindow = new BrowserWindow({
x: chatWindowState.x,
y: chatWindowState.y,
width: chatWindowState.width,
height: chatWindowState.height,
//frame: false,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
chatWindowState.manage(chatWindow);
var channel = await settings.get("twitch.channel") || 'xqc';
const twitchPanelBaseURL = `https://dashboard.twitch.tv/popout/u/${channel}/stream-manager`;
const alwaysontop = await settings.get("menu.alwaysontop");
// panels
console.log(alwaysontop, channel)
if (alwaysontop) {
BrowserWindow.getAllWindows()[0].setAlwaysOnTop(true, "floating");
} else {
BrowserWindow.getAllWindows()[0].setAlwaysOnTop(false);
}
const menu = [
{
label: 'Channel',
accelerator: process.platform === 'darwin' ? 'Alt+Cmd+C' : 'Alt+Ctrl+C',
click() {
prompt({
title: 'Enter your twitch username',
label: 'Twitch username:',
value: channel,
type: 'input',
alwaysOnTop: true,
})
.then((newChannel) => {
if(newChannel === null) {
} else {
channel = newChannel
settings.set("twitch", {
channel: newChannel,
});
chatWindow.loadURL('https://chitchat.ma.pe/' + newChannel);
//chatWindow.loadURL('https://www.twitch.tv/popout/'+ newChannel +'/chat?popout=')
}
})
.catch(console.error);
}
},
{
label: 'Settings',
click() {
chatWindow.webContents.executeJavaScript('document.querySelector(".setting button").click()');
}
},
{
label: 'Ver',
submenu: [
{
label: "Always on top",
type: "checkbox",
checked: alwaysontop,
click: function (item, browser) {
var state = item.checked;
if (state) {
BrowserWindow.getAllWindows()[0].setAlwaysOnTop(true, "floating");
} else {
BrowserWindow.getAllWindows()[0].setAlwaysOnTop(false);
}
settings.set("menu", {
alwaysontop: state,
});
},
},
{
type: 'separator',
},
{
label: 'Activity Feed',
click: function () {
donationsWindow = createPanel(460, 620, `https://yoink.streamelements.com/activity-feed?activitiesToolbar=false&popout=true&theme=dark&withSetupWizard=false`)
},
},
{
label: "Edit stream info",
click: function () {
editStreamInfoWindow = createPanel(460, 620, `${twitchPanelBaseURL}/edit-stream-info`)
}
},
{
label: "Quick Actions",
click: function () {
quickActionsWindow = createPanel(460, 620, `${twitchPanelBaseURL}/quick-actions`)
},
},
{
type: 'separator',
},
/*{
label: 'Open stream in Browser',
click: function(item, browser) {
shell.openExternal("https://www.twitch.tv/"+channel)
}
},
{
label: 'Open Player',
click: function(item, browser) {
activityFeedWindow = createPanel(100, 100, `https://player.twitch.tv/?channel=${channel}&parent=twitch.tv`)
}
},*/
/* {
label: "Paneles",
submenu: [
{
label: "Activity Feed",
type: "checkbox",
checked: activityFeed,
click: function (item, browser) {
url = ''
if (service == 'twitch') {
url = `${twitchPanelBaseURL}/activity-feed?uuid=1`
}else if(service == 'streamelements'){
url = 'https://yoink.streamelements.com/activity-feed?activitiesToolbar=false&popout=true&theme=dark&withSetupWizard=false'
}else if(service == 'streamlabs'){
url = 'https://streamlabs.com/dashboard/recent-events'
}
var state = item.checked;
if (state || activityFeedWindow) {
activityFeedWindow.close()
} else {
activityFeedWindow = createPanel(100, 100, url)
}
},
},
{
label: "Edit stream info",
type: "checkbox",
checked: editStreamInfo,
click: function (item, browser) {
var state = item.checked;
if (state || editStreamInfoWindow) {
editStreamInfoWindow.close()
} else {
editStreamInfoWindow = createPanel(460, 620, `${twitchPanelBaseURL}/edit-stream-info`)
}
settings.set("menu", {
editStreamInfo: state,
});
},
},
{
label: "Quick Actions",
type: "checkbox",
checked: quickActions,
click: function (item, browser) {
var state = item.checked;
if (state || quickActionsWindow) {
quickActionsWindow.close()
} else {
quickActionsWindow = createPanel(100, 100, `${twitchPanelBaseURL}/quick-actions`)
}
settings.set("menu", {
quickActions: state,
});
},
},
{
label: "Stream Preview",
type: "checkbox",
checked: streamPreview,
click: function (item, browser) {
var state = item.checked;
if (state || streamPreviewWindow) {
streamPreviewWindow.close()
} else {
streamPreviewWindow = createPanel(100, 100, `${twitchPanelBaseURL}/stream-preview`)
}
settings.set("menu", {
streamPreview: state,
});
},
},
{
label: "Moderation Actions",
type: "checkbox",
checked: moderationActions,
click: function (item, browser) {
var state = item.checked;
if (state || moderationActionsWindow) {
moderationActionsWindow.close()
} else {
moderationActionsWindow = createPanel(100, 100, `${twitchPanelBaseURL}/moderation-actions`)
}
settings.set("menu", {
moderationActions: state,
});
},
},
{
label: "Predictions",
type: "checkbox",
checked: predictions,
click: function (item, browser) {
var state = item.checked;
if (state || predictionsWindow) {
predictionsWindow.close()
} else {
predictionsWindow = createPanel(100, 100, `${twitchPanelBaseURL}/predictions`)
}
settings.set("menu", {
predictions: state,
});
},
},
{
label: "Stream Health",
type: "checkbox",
checked: streamHealth,
click: function (item, browser) {
var state = item.checked;
if (state || streamHealthWindow) {
streamHealthWindow.close()
} else {
streamHealthWindow = createPanel(100, 100, `${twitchPanelBaseURL}/stream-health`)
}
settings.set("menu", {
streamHealth: state,
});
},
},
{
label: "Ads",
type: "checkbox",
checked: ads,
click: function (item, browser) {
var state = item.checked;
if (state || adsWindow) {
adsWindow.close()
} else {
adsWindow = createPanel(100, 100, `${twitchPanelBaseURL}/streamer-ads-manager-panel`)
}
settings.set("menu", {
ads: state,
});
},
},
{
label: "Rewards Queue",
type: "checkbox",
checked: rewardQueue,
click: function (item, browser) {
var state = item.checked;
if (state || rewardQueueWindow) {
rewardQueueWindow.close()
} else {
rewardQueueWindow = createPanel(100, 100, `${twitchPanelBaseURL}/reward-queue`)
}
settings.set("menu", {
rewardQueue: state,
});
createPanel(100, 100, `${twitchPanelBaseURL}/reward-queue`)
},
},
{
label: "Auto Mod Queue",
type: "checkbox",
checked: quickActions,
click: function (item, browser) {
createPanel(100, 100, `${twitchPanelBaseURL}/auto-mod-queue`)
},
},
{
label: "Hosting You",
type: "checkbox",
checked: quickActions,
click: function (item, browser) {
createPanel(100, 100, `${twitchPanelBaseURL}/hosting-you`)
},
},
{
label: "Active Mods",
type: "checkbox",
checked: quickActions,
click: function (item, browser) {
createPanel(100, 100, `${twitchPanelBaseURL}/active-mods`)
},
},
{
label: "Unban Requests",
type: "checkbox",
checked: quickActions,
click: function (item, browser) {
createPanel(100, 100, `${twitchPanelBaseURL}/unban-requests`)
},
},
]
},*/
{ role: 'zoomin', accelerator: 'CommandOrControl+=' },
{ role: 'zoomout' },
{
label: 'Recargar',
accelerator: "CmdOrCtrl+R",
click: () => {
chatWindow.reload();
}
},
]
}
];
chatWindow.setMenu(Menu.buildFromTemplate(menu))
// Loads the twitch's chat popup for the user channel
//chatWindow.loadURL(`https://www.twitch.tv/popout/${channel}/chat?popout=`)
chatWindow.loadURL(`https://chitchat.ma.pe/${channel}`)
// loads BTTV, FFZ and 7tv
//session.defaultSession.loadExtension(isDev ? localPath : extensionPath)
/*var script = fs.readFileSync('script_prod.js', 'utf8');
console.log(script)*/
// Add an item to the context menu that appears only when you click on an image
contextMenu({
prepend: (defaultActions, parameters, browserWindow) => [{
label: 'Ver perfil',
click: (menuItem, browserWindow, event) => {
console.log(parameters)
chatWindow.webContents.executeJavaScript(`
var usernameCard = document.elementFromPoint(${parameters.x}, ${parameters.y}).innerText;
window.open('https://www.twitch.tv/popout/${channel}/viewercard/'+usernameCard, '_blank').focus();
`)
}
}]
});
script = fs.readFileSync('script_prod.js', 'utf8')
chatWindow.webContents.on('dom-ready', async () => {
//loadEmotes(chatWindow)
/*
script = await axios.get(
'https://raw.githubusercontent.com/elmarceloc/EZ-Chat/master/script_prod.js?nocache=' + Math.random()*1000
)*/
//script = script.data
chatWindow.webContents.executeJavaScript(script)
})
// open urls in the default browser
chatWindow.webContents.on('new-window', function(e, url) {
e.preventDefault();
require('electron').shell.openExternal(url);
});
// Open the DevTools.
if (isDev) chatWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.