Skip to content

Commit

Permalink
fix PS3 web render on silk+webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
yne committed Apr 22, 2023
1 parent c018935 commit 0ed7a1a
Showing 1 changed file with 66 additions and 48 deletions.
114 changes: 66 additions & 48 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,63 @@
<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="hidden" size="55" name="disclamer" value="PS3 web browser can't download JS-generated RAP => use a PC" disabled><br>
<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()">
</form>
</header>
<ul id="list"></ul>
<script>
$ = document.querySelector.bind(document);
var DB = [];
var url = 'db.csv';
function makeRap(row) {
var hex = row[4];
if (!hex) return ""
if (hex == 0) return '<span title="Press Circle in ReactPSN to activate this game">(o)</span>'//\u233E\u25CB\u26AA\u29BF\u29BE
return '<a download="' + row[1] + '-' + row[0] + '_00-' + hex.substr(16) + '.rap" href="data:application/stream;base64,' + btoa((hex.match(/../g) || []).map(function (x) { return String.fromCharCode(parseInt(x, 16)) }).join('')) + '">RAP</a>'
}
function searchDB(q, out) {
//$("#about").hidden = !(out.hidden = !q);
var rule = new RegExp(decodeURIComponent(q), 'i');
out.innerHTML = DB.filter(function (a) { return a[5].match(rule) }).slice(0, 100).map(function (a) { return '<li><a href="http://zeus.dl.playstation.net/cdn/' + a[1] + '/' + a[0] + '_00/' + a[2] + '.pkg">' + a[5] + ' ' + (a[3]) + ' (' + a[0][2] + ")</a> " + makeRap(a) + "</li>" }).join('')
}
function loadDB(force) {
$('#q').disabled = !localStorage['DB'];
if (!localStorage['DB'] || force) {//DB not in cache or force reload
$('#q').placeholder = "Loading DataBase ..."
try {
var isPS3 = navigator.userAgent.match(/playstation/i);
var f = document.forms.engine;
if(navigator.userAgent.match(/playstation/i))f.disclamer.type='text'
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.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();
$('#b').disabled = true;
xhr.onabort = xhr.ontimeout = xhr.onerror = function (ev) {
$('#b').disabled = false;
$('#q').placeholder = "Unable to load Database"
}
xhr.onload = function (ev) {//xhr.onloadend
$('#b').disabled = false;
localStorage['DB'] = JSON.stringify(ev.target.response.split("\n").map(function (c) { return c.split(',') }))
loadDB();//now that the DB is in localstorage, do a self-call
}
xhr.open('GET', url);
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();
} else {
DB = JSON.parse(localStorage['DB'])
$('#q').placeholder = "Search in " + DB.length + " url"
document.body.onhashchange()//trigger a hash search (if any)
}
}
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 rule = new RegExp(decodeURIComponent(location.hash.replace(/^#+/, '')), 'i');
document.getElementById('list').innerHTML = "";
for (var i = 0, found = 0; i < DB.length && found < 50; i++) {
if (!DB[i][5].match(rule)) continue;
found++;
var a = DB[i];
document.getElementById('list').innerHTML += '<li><a href="http://zeus.dl.playstation.net/cdn/' + a[1] + '/' + a[0] + '_00/' + a[2] + '.pkg">' + a[5] + ' ' + (a[3]) + ' (' + a[0][2] + ")</a> " + makeRap(a) + "</li>";
}
};
f.query.value = location.hash.replace(/^#+/, '');
// document.body.onhashchange = render; dont work on Silk engine
render();
if (!DB.length) {
fetchDB()
}
} catch (a) { alert(a) }
</script>
<style>
form,
Expand All @@ -56,6 +75,18 @@
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;
Expand All @@ -72,17 +103,4 @@
input {
font-size: 1.5em
}
</style>
<body onload="loadDB()" onhashchange="try{searchDB(document.location.hash.substr(1),$('#list'))}catch(e){alert(e)}">
<header>
<a id="about" href="https://github.com/yne/psndl">
<img height="100"
src='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 5"><path d="M13,5 13,0 14,1 14,4 15,4 16,5 M2,5 3,4 4,4 4,1 5,0 7,0 6,1 5,1 5,4 4,5 M6,4 6,2 7,1 7,2 8,3 8,0 9,1 9,4 8,5 8,4 7,3 7,5 M9,5 10,4 11,4 11,1 10,1 9,0 11,0 12,1 12,4 11,5 M0,5 0,3 1,2 2,2 2,1 1,1 0,0 2,0 3,1 3,2 2,3 1,3 1,4"></path></svg>'>
</a>
<form onsubmit="document.location.hash=this.elements['q'].value;return false;">
<input type="text" size=25 id="q" onkeyup="this.form.onsubmit()" />
<input type="button" id="b" onclick="loadDB(true)" value="🔄" title="reload DB" />
</form>
</header>
<ul id="list"></ul>
</body>
</style>

0 comments on commit 0ed7a1a

Please sign in to comment.