-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
257 lines (215 loc) · 5.81 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Steins;Gate Episode Finder</title>
<link rel="icon" type="image/x-icon" href="assets/fav.ico">
<style>
html {
height: 100%;
}
body {
background-image: url("assets/steins.webp");
background-repeat: no-repeat;
background-size: cover;
background-color: #111;
color: #fff;
font-family: 'Arial', sans-serif;
text-align: center;
padding: 20px;
height: 100%;
}
h1 {
font-size: 36px;
margin-bottom: 20px;
}
#imageContainer {
margin-top: 20px;
}
#imageContainer img {
border: 3px solid #ccc;
border-radius: 10px;
max-width: 708px;
max-height: 400px;
}
input[type="file"] {
display: none;
}
label {
background-color: #4CAF50;
color: white;
padding: 15px 30px;
font-size: 18px;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}
label:hover {
background-color: #45a049;
}
#findEpisodeBtn {
background-image: url("assets/button.webp");
background-size: 40px 40px;
background-repeat: no-repeat;
background-position: 0px 4px;
background-color: #3498db;
text-align: right;
color: white;
padding: 15px 30px;
font-size: 18px;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}
#findEpisodeBtn:hover {
background-color: #2980b9;
}
h2 {
color: #2980b9;
text-align: left;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 10px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
}
</style>
</head>
<body>
<img src="assets/title.webp">
<h1>Episode Finder</h1>
<label for="imageInput">Upload Image</label>
<input type="file" id="imageInput" accept="image/*" onchange="displayImage()">
<button id="findEpisodeBtn">Find Episode</button>
<div id="imageContainer"></div>
<h2>Episodes:</h2>
<table id="episodeTable">
<thead>
<tr>
<th>Anime</th>
<th>Episode</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody id="episodeList"></tbody>
</table>
<script async type="text/javascript" src="find_ep.js"></script>
<script>
const NUM_FOUND = 20;
const anime_names = [
"Steins;Gate",
"Steins;Gate: Oukoubakko no Poriomania (ep25)"
];
var Module = {
onRuntimeInitialized: function() {
var btn = document.getElementById('findEpisodeBtn');
btn.addEventListener('click', function() {
processImage();
});
},
};
function displayImage() {
const input = document.getElementById('imageInput');
const container = document.getElementById('imageContainer');
if (input.files && input.files[0]) {
const reader = new FileReader();
reader.onload = function (e) {
const img = new Image();
img.src = e.target.result;
container.innerHTML = '';
container.appendChild(img);
};
reader.readAsDataURL(input.files[0]);
clearEpisodeTable();
}
}
function arrayToPtr(array, bytes_per_element) {
var ptr = Module._malloc(array.length * bytes_per_element)
Module.HEAP32.set(array, ptr / bytes_per_element)
return ptr
}
function ptrToArray(ptr, length, bytes_per_element) {
var array = new Int32Array(length)
var pos = ptr / bytes_per_element
array.set(Module.HEAP32.subarray(pos, pos + length))
return array
}
function processImage() {
const image = document.getElementById('imageContainer').
getElementsByTagName('img')[0];
if (!image) {
alert("Please choose an image first!");
return;
}
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0, image.width, image.height);
/* Allocate image. */
const imageData = ctx.getImageData(0, 0, image.width, image.height);
const data = imageData.data;
const numBytes = data.length * data.BYTES_PER_ELEMENT;
const dataPtr = Module._malloc(numBytes);
const dataOnHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr,
numBytes);
dataOnHeap.set(data);
/* Allocate pointers to frames/episodes/anime_id. */
frames = Array(NUM_FOUND).fill(-1)
episodes = Array(NUM_FOUND).fill(-1)
anime_id = Array(NUM_FOUND).fill(-1)
frames_ptr = arrayToPtr(frames, 4)
episodes_ptr = arrayToPtr(episodes, 4)
anime_id_ptr = arrayToPtr(anime_id, 4)
Module._find_episode(
dataOnHeap.byteOffset, canvas.width, canvas.height,
frames_ptr, episodes_ptr, anime_id_ptr);
frames = ptrToArray(frames_ptr, NUM_FOUND, 4)
episodes = ptrToArray(episodes_ptr, NUM_FOUND, 4)
anime_id = ptrToArray(anime_id_ptr, NUM_FOUND, 4)
console.log(frames);
console.log(episodes);
console.log(anime_id);
Module._free(dataPtr);
Module._free(frames_ptr);
Module._free(episodes_ptr);
Module._free(anime_id_ptr);
/* Add episodes into the table. */
clearEpisodeTable()
for (i = 0; i < frames.length; i++) {
if (frames[i] == -1)
break;
addRow(anime_id[i], episodes[i], frames[i]);
}
}
function addRow(anime, episode, timestamp) {
const episodeTable = document.getElementById('episodeList');
const row = episodeTable.insertRow();
const titleCell = row.insertCell(0);
const episodeCell = row.insertCell(1);
const timeCell = row.insertCell(2);
const minutes = parseInt(timestamp/6/60);
const seconds = parseInt((timestamp/6)%60);
const real_ts =
minutes.toString().padStart(2, '0') +
":" +
seconds.toString().padStart(2, '0');
titleCell.textContent = anime_names[anime];
episodeCell.textContent = episode;
timeCell.textContent = real_ts;
}
function clearEpisodeTable() {
const table = document.getElementById("episodeList");
table.innerHTML = "";
}
</script>
</body>
</html>