forked from alairon/SwitchRP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (116 loc) · 4.46 KB
/
index.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
/* index.js
* Functions used by the client-side window
* Includes functions used by both HTML and electron
*/
/* eslint-disable */
// IPC Renderer
const { ipcRenderer } = require('electron');
// File containing list of games
const gameList = require('./titles.json');
/** IPC Renderer Function
* Sends a signal to main.js to update the user's discord status
*/
// Provides functionality to the 'Update Status' button in index.html
const updateStatus = document.getElementById('updateStatus');
updateStatus.addEventListener('click', () => {
const clientAppID = document.getElementById('gameID').value
const gameDetails = document.getElementById('gameDetails').value
const largeImageKey = Object.values(gameList)[document.getElementById('titleName').value].largeImageKey;
ipcRenderer.send('updateStat', clientAppID, gameDetails, largeImageKey);
});
/** Game Titles
* Functions that insert a list of games found from the specified JSON file.
*/
// Add titles from gameList into the dropdown menu
document.addEventListener('DOMContentLoaded', () => {
const dropdownDiv = document.createDocumentFragment();
for (let x = 0; x < Object.keys(gameList).length; x++) {
const gameItem = document.createElement('button');
const listObj = Object.values(gameList)[x];
/* Produces a clickable dropdown item:
<button class="dropdown-item" type="button" onclick="setTitle ${listObj.id}">
listObj.longName
</button>
*/
gameItem.setAttribute('class', 'dropdown-item');
gameItem.setAttribute('type', 'button');
gameItem.setAttribute('onclick', `setTitle("${listObj.id}")`);
gameItem.setAttribute('value', listObj.id);
gameItem.innerHTML = listObj.longName;
dropdownDiv.appendChild(gameItem);
}
document.getElementById('gameList').appendChild(dropdownDiv);
});
// Sets the text of the dropdown menu to what the user selected
function setTitle(id) {
const titleName = document.getElementById('titleName');
const listObj = Object.values(gameList)[id];
document.getElementById('gameName').value = listObj.longName;
document.getElementById('gameID').value = listObj.clientAppID;
titleName.value = id;
titleName.innerHTML = '<i class="fas fa-check"></i> Game selected';
}
/** Themes
* Allows the user to select between a light and dark theme
*/
// Toggles the interface between its light and dark variants
function toggleScheme() {
const core = document.getElementById('bodyMain');
const lightbulb = document.getElementById('lightToggle');
const resetButton = document.getElementById('reset-btn');
if (lightbulb.value == '0') {
// Light -> Dark
lightbulb.value = '1';
lightbulb.innerHTML = '<i class="fas fa-lightbulb"></i>';
core.classList.add('body-dark');
core.classList.remove('body-light');
resetButton.classList.add('btn-outline-light');
resetButton.classList.remove('btn-outline-dark');
} else {
// Dark -> Light
lightbulb.value = '0';
lightbulb.innerHTML = '<i class="far fa-lightbulb"></i>';
core.classList.add('body-light');
core.classList.remove('body-dark');
resetButton.classList.add('btn-outline-dark');
resetButton.classList.remove('btn-outline-light');
}
}
/** Page Reset
* Restores the initial values on the form to its initial state
*/
function resetValues() {
document.getElementById('titleName').innerHTML = '<i class="fas fa-gamepad"></i> Select your game';
document.getElementById('titleName').value = '';
document.getElementById('gameName').value = '';
document.getElementById('gameID').value = '';
document.getElementById('gameDetails').value = '';
}
/** Messaging System
* Allows users to read preconstructed notices, or ones generated by the system
*/
function readMail(){
const mail = document.getElementById('noticesButton');
const notice = document.getElementById('notices');
switch (mail.value) {
//Open unread message
case('0'):
mail.value = '1';
mail.classList.add('btn-light');
mail.classList.remove('btn-warning');
mail.innerHTML = '<i class="fas fa-envelope-open-text"></i>';
notice.setAttribute ('style', 'display:block');
break;
//Close read message
case('1'):
mail.value = '2';
mail.innerHTML = '<i class="fas fa-envelope"></i>';
notice.setAttribute ('style', 'display:none');
break;
//Open read message
default:
mail.value = '1';
mail.innerHTML = '<i class="fas fa-envelope-open-text"></i>';
notice.setAttribute ('style', 'display:block');
}
}