-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
executable file
·62 lines (56 loc) · 2.04 KB
/
search.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
function clearResults() {
var container = document.getElementById("results");
while (container.firstChild) {
container.removeChild(container.firstChild);
}
}
function displayResults(res) {
clearResults();
var container = document.getElementById("results");
for (var i = 0; i < res.length; i++) {
var elem = document.createElement("div");
var title = document.createElement("b");
var region = document.createElement("a");
var select = document.createElement("a");
title.innerText = res[i][1] + " ";
region.innerText = res[i][2] + " ";
select.href = "game.php?id=" + res[i][0];
select.innerText = "Select";
elem.className = 'searchitem';
elem.appendChild(title);
elem.appendChild(region);
elem.appendChild(select);
container.appendChild(elem);
}
}
initSqlJs().then(function(SQL) {
var xhr = new XMLHttpRequest();
// For example: https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite
xhr.open("GET", "openvgdb.sqlite", true);
xhr.responseType = "arraybuffer";
xhr.onload = e => {
document.getElementById("overlay").style.display = "none";
var uInt8Array = new Uint8Array(xhr.response);
var db = new SQL.Database(uInt8Array);
var contents = db.exec("SELECT romID, releaseTitleName, TEMPregionLocalizedName FROM RELEASES");
var select = document.getElementById("search");
select.oninput = function() {
// var result = fuse.search(search.value);
// result = result.slice(0, 100);
if (select.value.length == 0) {
clearResults();
return;
}
displayResults(contents[0].values.filter(function(value) {
for (var i = 0; i < Math.min(value[1].length, select.value.length); i++) {
if (value[1][i].toLowerCase() != select.value[i].toLowerCase()) {
return false;
}
}
return true;
}).slice(0, 100));
};
// contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]
};
xhr.send();
});