This repository was archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcachegame.html
169 lines (167 loc) · 6.84 KB
/
cachegame.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
<!DOCTYPE html>
<html>
<head>
<title>okrEMU</title>
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel='stylesheet' href='css/styledselect.css'>
<link rel='stylesheet' href='css/index-main.css'>
<!-- android -->
<meta name="mobile-web-app-capable" content="yes">
<!-- iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="translucent-black">
<meta name="apple-mobile-web-app-title" content="okrEMU">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel='stylesheet' href='css/styledselect.css'>
<link rel='stylesheet' href='css/index-main.css'>
</head>
<body>
<div id='titlebar'>
<h2 style='display: inline-block; font-size: 75px; margin-bottom: -60px;'>Cache Games</h2>
<a href='options.html' style='display: inline-block;'>Back to Options</a>
</div>
<div class="custom-select" style="width: 25%; display: inline-block;">
<select id='chooseconsole'>
<option value="0" selected="selected">All</option>
<option value="1">NES</option>
<option value="2">SNES</option>
<option value="3">GBA</option>
</select>
</div>
<input type="text" id="search" name="search-okremu" placeholder='Search...' style='display: inline-block;' autocomplete="off">
<br><br>
<div id='nes'></div>
<div id='snes'></div>
<div id='gba'></div>
<script src="scripts/fastclick.js"></script>
<script src='scripts/styledselect.js'></script>
<script src='localForage/dist/localforage.js'></script>
<script src='scripts/gameVals.js'></script>
<script>
window.addEventListener("touchstart", e => {
if(e.touches.length > 1) {
e.preventDefault();
} else {
return;
}
}, {passive: false});
window.addEventListener("touchmove", e => {
if(e.touches.length > 1) {
e.preventDefault();
} else {
return;
}
}, {passive: false});
window.addEventListener("touchend", e => {
if(e.touches.length > 1) {
e.preventDefault();
} else {
return;
}
}, {passive: false});
gameVals.sort(function(a, b){
var intArray = [a[4], b[4]]
intArray.sort();
if(intArray.join('\\') === [a[4], b[4]].join('\\')){
return -1;
} else {
return 1;
}
});
gameVals.forEach(setUpImgs);
setInterval(function(){
document.getElementsByTagName('select')[0].dispatchEvent(new Event('change'));
document.getElementsByClassName('select-selected')[0].innerHTML = document.getElementById('chooseconsole').getElementsByTagName('option')[document.getElementById('chooseconsole').selectedIndex].innerHTML;
if(document.getElementById('search').value !== '' && document.getElementById('search').value !== null && document.getElementById('search').value !== undefined){
for(var i = 0; i < gameVals.length; i++){
if(gameVals[i][4].toLowerCase().indexOf(document.getElementById('search').value.toLowerCase()) === -1){
document.getElementById(gameVals[i][0]).style.display = 'none';
} else {
document.getElementById(gameVals[i][0]).style.display = 'inline-block';
}
}
} else {
for(var i = 0; i < gameVals.length; i++){
document.getElementById(gameVals[i][0]).style.display = 'inline-block';
}
}
}, 0);
document.getElementById('chooseconsole').addEventListener('change', (e) => {
var selval = e.target.value;
if(selval === '0'){
for(var i = 0; i < divids.length; i++){
document.getElementById(divids[i]).style.display = 'block';
}
} else if(selval === '1'){
for(var i = 0; i < divids.length; i++){
if(divids[i] === 'nes'){
document.getElementById(divids[i]).style.display = 'block';
} else {
document.getElementById(divids[i]).style.display = 'none';
}
}
} else if(selval === '2'){
for(var i = 0; i < divids.length; i++){
if(divids[i] === 'snes'){
document.getElementById(divids[i]).style.display = 'block';
} else {
document.getElementById(divids[i]).style.display = 'none';
}
}
} else if(selval === '3'){
for(var i = 0; i < divids.length; i++){
if(divids[i] === 'gba'){
document.getElementById(divids[i]).style.display = 'block';
} else {
document.getElementById(divids[i]).style.display = 'none';
}
}
}
});
async function setUpImgs(item, index){
var gameImg = document.createElement('IMG');
gameImg.id = item[0];
gameImg.src = item[3];
gameImg.height = '256';
gameImg.style.cursor = 'pointer';
var cachedCheck = await localforage.getItem(item[0]);
var isCached;
if(cachedCheck == undefined || cachedCheck == null) {
isCached = false;
gameImg.style.border = "thick solid red";
} else {
gameImg.classList.add('cached');
gameImg.style.border = "thick solid green";
}
document.getElementById(item[2]).appendChild(gameImg);
document.getElementById(item[0]).addEventListener("click", async function(){
if(this.classList.contains('cached')) {
this.classList.remove('cached');
this.style.border = "thick solid yellow";
await localforage.removeItem(this.id);
this.style.border = "thick solid red";
} else {
this.classList.add('cached');
async function startCachingGame(gameobj) {
var gameText;
var gameTextCheck;
gameobj.style.border = "thick solid blue";
async function setTextToUrl(url){gameText = await fetch(url).then(r => r.blob());}
await setTextToUrl('https://corsbyp.herokuapp.com/https://drive.google.com/uc?export=download&id=' + gameobj.id);
await localforage.setItem(gameobj.id, gameText);
if(false) {
console.log('data incorrect. retrying.');
startCachingGame(gameobj);
} else {
gameobj.style.border = "thick solid green";
}
}
startCachingGame(this);
}
});
}
</script>
</body>
</html>