This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlay-script.js
126 lines (114 loc) · 4.19 KB
/
overlay-script.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
const { ipcRenderer, remote } = require('electron')
if (localStorage.getItem('first-time') === undefined){
localStorage.setItem('theme', 'dark')
} else {
localStorage.setItem('first-time', false)
}
let volumeCache = '100%'
let time = '0:00'
let thumb = 'assets/overlay/artwork.png'
let theme = localStorage.getItem('theme')
//Checks what theme to use
if (theme === 'light'){
document.querySelector('#theme').href='light-overlay.css'
} else {
document.querySelector('#theme').href='dark-overlay.css'
}
document.querySelector('.play').addEventListener('click', function(){
ipcRenderer.send('overlay-play-pause')
});
document.querySelector('.pause').addEventListener('click', function(){
ipcRenderer.send('overlay-play-pause')
});
document.querySelector('.next').addEventListener('click', function(){
ipcRenderer.send('overlay-next')
});
document.querySelector('.previous').addEventListener('click', function(){
ipcRenderer.send('overlay-previous')
});
document.querySelector('.up').addEventListener('click', function(){
ipcRenderer.send('overlay-volume-up')
})
document.querySelector('.down').addEventListener('click', function(){
ipcRenderer.send('overlay-volume-down')
})
document.querySelector('#open-app').addEventListener('click', function(){
ipcRenderer.send('open-mainWindow');
})
document.getElementsByTagName('body')[0].addEventListener('click', (e) => {
if (e.target.className === 'close-overlay'){
ipcRenderer.send('overlay-close')
}
})
//Button to change the theme
document.querySelector('#switch').addEventListener('click', function(){
if (theme === 'dark'){
document.querySelector('#theme').href='light-overlay.css'
localStorage.setItem('theme', 'light')
theme = 'light'
} else {
document.querySelector('#theme').href='dark-overlay.css'
localStorage.setItem('theme', 'dark')
theme = 'dark'
}
})
//Button to open next playing view
document.querySelector('#more').addEventListener('click', function(){
document.getElementsByClassName('overlay-next-playing')[0].style.display='block'
})
setInterval(() => {
ipcRenderer.send('request-volume-data')
ipcRenderer.send('request-time-data')
ipcRenderer.send('request-overlay-data')
}, 100);
ipcRenderer.on('requested-time-data', function(event, arg){
if (arg == undefined){
time = '0:00'
} else {
time = arg
localStorage.setItem('time', time)
}
document.querySelector('#timestamp').innerText=localStorage.getItem('time')
})
ipcRenderer.on('requested-volume-data', function(event, arg){
if (arg == undefined){
volumeCache = 0 + '%'
} else {
volumeCache = arg +'%'
localStorage.setItem('volumeCache', volumeCache)
}
document.querySelector('.value').innerText=localStorage.getItem('volumeCache')
})
ipcRenderer.on('requested-overlay-data', function(event, arg){
if (arg[4] === undefined || arg[4] === null || arg[4] === 'https://music.youtube.com/'){
//nothing
} else {
thumb = arg[4]
}
})
ipcRenderer.on('requested-overlay-data', function(event, arg){
if (arg[6] === false || arg[6] === null || arg[6] === undefined){
document.querySelector('.DRPStatus-text').innerText='Discord is disconnected'
document.querySelector('.circle').style.background='#d23636'
} else {
document.querySelector('.DRPStatus-text').innerText='Discord is connected'
document.querySelector('.circle').style.background='#45d471'
}
})
ipcRenderer.on('requested-overlay-data', function(event, arg){
if (arg[0] == 'Title' && arg[1] == 'Artist'){
//do nothing
} else {
document.querySelector('.title').innerText=arg[0]
document.querySelector('.artist').innerText=arg[1]
document.querySelector('#end-timestamp').innerText=arg[3]
document.querySelector('#albumImg').src=thumb
if (arg[5] === 'paused'){
document.querySelector('.pause').style.display='none'
document.querySelector('.play').style.display='inline-block'
} else {
document.querySelector('.play').style.display='none'
document.querySelector('.pause').style.display='inline-block'
}
}
})