-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
128 lines (122 loc) · 3.93 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
<!DOCTYPE html>
<html lang="en">
<meta charset="utf8">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<meta content="width=device-width, user-scalable=no" name="viewport" />
<title>PSNDL</title>
<header>
<a href="https://github.com/yne/psndl">PSNDL</a>
<form name="engine" onsubmit="location.hash=query.value;render();return false">
<input type="search" name="query" size="25">
<input type="submit" name="send" value="search" disabled>
<input type="button" name="fetch" value="reload database" onclick="fetchDB()">
<ul id="letters"><button type="button" onclick="location.hash='^'+this.innerHTML;render()">[0-9]</button></ul>
</form>
</header>
<ul id="list"></ul>
<script>
function sort(lines, algo) {
for (var i = 0; i < lines.length; i++) {
for (var j = 0; j < lines.length - i - 1; j++) {
if (algo(lines[j], lines[j + 1])) {
var temp = lines[j];
lines[j] = lines[j + 1];
lines[j + 1] = temp;
}
}
}
return lines;
}
try {
var f = document.forms.engine;
var DB = window.localStorage ? JSON.parse(localStorage.DB || '[]') : [];
function makeRap(row) {
var hex = row[4];
if (!hex) return "";
if (hex == 0) return '<span>press Circle in ReactPSN</span>';
return '<a download="' + row[1] + '-' + row[0] + '_00-' + hex + '.rap" href="' + hex + '.rap">RAP</a>';
//return '<a download="' + row[1] + '-' + row[0] + '_00-' + hex.substr(16) + '.rap" href="data:application/octet-stream,' + hex.replace(/../g, function(a){ return '%'+a;}) + '">RAP</a>';
}
function fetchDB() {
f.fetch.disabled = true;
var xhr = new XMLHttpRequest();
xhr.onabort = xhr.ontimeout = xhr.onerror = alert;
xhr.onload = function () { // PS3 slik engine don't receive arguments ?!
if (xhr.status != 200) return alert(xhr.status);
DB = xhr.responseText.split("\n");
for (var i = 0; i < DB.length; i++)DB[i] = DB[i].split(",");
if (window.localStorage) { localStorage.DB = JSON.stringify(DB); }
f.fetch.disabled = false;
render();
};
xhr.open('GET', 'db.csv');
xhr.send();
}
function render() {
f.fetch.type = window.localStorage ? 'button' : 'hidden'; // hide refresh
f.send.disabled = DB.length == 0;
f.query.placeholder = DB.length + " URL loaded";
var query = decodeURIComponent(location.hash.replace(/^#+/, ''));
var startsWith = query.length && query[0] == '^';
var rule = new RegExp(query, 'i');
var matches = [];
for (var i = 0; i < DB.length && matches.length < (startsWith ? 999 : 99); i++) {
if (DB[i][5].match(rule) || (DB[i][0] == query))
matches.push(DB[i]);
}
sort(matches, function (a, b) { return a[5] > b[5]; });
for (var i = 0; i < matches.length; i++) {
var a = matches[i];
matches[i] = '<li><a href="http://zeus.dl.playstation.net/cdn/' + a[1] + '/' + a[0] + '_00/' + a[2] + '.pkg">' + a[5] + ' ' + (a[3]) + ' [' + a[0] + "]</a> " + makeRap(a) + "</li>";
}
document.getElementById('list').innerHTML = matches.join('');
};
var buttons = '';
for (var c = 65; c < 91; c++) {
buttons += '<button type="button" onclick="location.hash=\'^\'+this.innerHTML;render()">' + String.fromCharCode(c) + '</button>';
}
document.getElementById("letters").innerHTML += buttons;
f.query.value = location.hash.replace(/^#+/, '');
// document.body.onhashchange = render; // dont work on Silk engine, but still usefull for other
render();
if (!DB.length) {
fetchDB()
}
} catch (a) { alert(a) }
</script>
<style>
form,
img,
ul {
display: block;
margin: 2em auto;
}
header {
display: block;
text-align: center;
}
header>a {
font-size: 6em;
text-decoration: none;
font-family: monospace;
font-weight: bold;
color: initial;
}
header>a:hover {
text-decoration: inherit;
}
[download] {
text-decoration: none;
padding: 1px 8px;
color: black !important;
border: 1px solid #444;
border-radius: 3px;
}
li {
line-height: 1.5em;
list-style: none;
}
input {
font-size: 1.5em
}
</style>