This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
157 lines (145 loc) · 4.51 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
/*
* Redirects to each files own site.
*
* @param {string} file The file to load.
*/
function load (file) {
location.search = '?game=' + file;
}
/*
* Loads presets.
*
* @param {string} id The ID of the option activated.
*/
function loadPreset (id) {
var name = id.substring(0, id.length - 1);
var num = id[id.length - 1];
if (ver.minor >= 1) {
var presetList = xml.querySelectorAll('presetlist preset');
} else {
var presetList = xml.querySelectorAll('presets preset');
}
for (let num2 = 0; num2 < presetList.length; num2++) {
if (presetList[num2].getAttribute('name').replace(/[^\w\s]/gi, '').replace(/ /g,"_") === name) {
var toggleList = presetList[num2].querySelectorAll('preset option')[num].querySelectorAll('option toggle');
for (let num3 = 0; num3 < toggleList.length; num3++) {
if (toggleList[num3].getAttribute('type') == null) {
var arr = document.querySelectorAll('.flexColumn[content="' + toggleList[num3].getAttribute('content') + '"]');
} else {
var arr = document.querySelectorAll('.flexColumn[content="' + toggleList[num3].getAttribute('content') + '"][type="' + toggleList[num3].getAttribute('type') + '"]');
}
var force = toggleList[num3].getAttribute('force');
for (let num4 = 0; num4 < arr.length; num4++) {
switch (force) {
case 'show':
arr[num4].style.display = '';
break;
case 'hide':
arr[num4].style.display = 'none';
break;
default:
if (arr[num4].style.display != 'none') {
arr[num4].style.display = 'none';
} else {
arr[num4].style.display = '';
}
}
}
}
return;
}
}
}
/*
* Toggles table of contents visibility.
*/
function toggleContents () {
var elem = document.getElementById('contentsWrapper');
if (document.getElementById('contentsShow').innerText === 'Hide') {
elem.style.height = 0;
document.getElementById('contentsShow').innerText = 'Show';
document.getElementById('contentsTitle').style.borderColor = 'transparent';
} else {
var wrapper = document.getElementById('contents');
elem.style.height = wrapper.clientHeight + "px";
document.getElementById('contentsShow').innerText = 'Hide';
document.getElementById('contentsTitle').style.borderColor = '#a9a9a963';
}
}
/*
* Opens Settings.
*/
function openSettings () {
document.getElementById('settingsWrapper').style.visibility = 'visible';
document.getElementById('settingsWrapper').style.opacity = 1;
}
/*
* Closes Settings.
*/
function closeSettings () {
document.getElementById('settingsWrapper').style.opacity = 0;
document.getElementById('settingsWrapper').style.visibility = 'hidden';
}
/*
* Activates or deactivates the custom theme.
*/
function changeDefaultTheme () {
if (document.getElementById('defaultTheme').checked === true) {
location.search = location.search + '&defTheme=1&showSettings=1';
localStorage.setItem('defTheme', 1);
} else {
loadStyles();
localStorage.setItem('defTheme', 0);
}
}
var sheet = window.document.styleSheets[0];
/*
* Adds a single CSS rule.
*
* @param {string} selector The selector
* @param {string} property The property
* @param {string} value The value
*/
function addCSSRule (selector, property, value) {
sheet.insertRule(selector + ' { ' + property + ': ' + value + ' !important; } ', sheet.cssRules.length);
}
/*
* Creates an element and returns it.
*
* @param {string} type The element type it should be.
* @param {string/DOM Element} parent The parent element, if an id is given it gets the DOM Element of it
*/
function cElem (type, parent) {
if (typeof parent === 'string') {
parent = document.getElementById(parent);
}
var elem = document.createElement(type);
parent.appendChild(elem);
return elem;
}
/*
* Gets variable from URL and returns it, returns false if it doesn't exist.
*
* @param {string} variable The variable it should get.
*/
function getUrl(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
/*
* Closes the settings if the user doesn't click on the settings while they are opened.
*
* @param {string} event What event got fired.
*/
function windowOnClick (event) {
var settings = document.querySelector("#settingsWrapper");
if (event.target === settings) {
closeSettings();
}
}
window.addEventListener("click", windowOnClick);