feat: go back to random result

This commit is contained in:
relikd
2024-02-29 02:38:17 +01:00
parent 105f82ef50
commit dff67ca0b8
2 changed files with 27 additions and 29 deletions

View File

@@ -2,8 +2,9 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0" /> <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
<meta name="referrer" content="no-referrer">
<title>IPA Archive</title> <title>IPA Archive</title>
<link rel="shortcut icon" href="./favicon.ico"> <link rel="shortcut icon" href="./favicon.ico">
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon.png">
@@ -58,20 +59,6 @@
<div><a onclick="searchBundle($IDX)">Show all</a></div> <div><a onclick="searchBundle($IDX)">Show all</a></div>
</div> </div>
</div> </div>
<div class="entry single">
<div>
<img src="$IMG">
<button onclick="installIpa($IDX)">Install</button>
</div>
<div class="info">
<h4>$TITLE</h4>
<div>BundleId: $BUNDLEID</div>
<div>Version: v$VERSION $SIZE</div>
<div>Device: $PLATFORM</div>
<div>Minimum OS: $MINOS</div>
<div>Link: <a href="$URL" rel="noopener noreferrer nofollow">$URLNAME</a></div>
</div>
</div>
<div class="itunes"> <div class="itunes">
<h4>iTunes Info:</h4> <h4>iTunes Info:</h4>
<div>Genre: $GENRES</div> <div>Genre: $GENRES</div>
@@ -85,6 +72,7 @@
<p>$DESCRIPTION</p> <p>$DESCRIPTION</p>
</div> </div>
<a class="screenshot" href="$URL" target="_blank"><img src="$URL"></a> <a class="screenshot" href="$URL" target="_blank"><img src="$URL"></a>
<p class="randomAllVer"> <a onclick="searchBundle($IDX, '&random=$IDX')">show all versions</a></p>
</div> </div>
<div id="overlay" hidden> <div id="overlay" hidden>

View File

@@ -130,13 +130,17 @@ function applySearch() {
function restoreSearch() { function restoreSearch() {
location.hash = previousSearch; location.hash = previousSearch;
loadConfig(false); const conf = loadConfig(false);
previousSearch = ''; previousSearch = '';
searchIPA(true); if (conf.random) {
randomIPA(conf.random);
} else {
searchIPA(true);
}
} }
function searchBundle(idx) { function searchBundle(idx, additional) {
previousSearch = location.hash; previousSearch = location.hash + (additional || '');
document.getElementById('bundleid').value = DB[idx][4]; document.getElementById('bundleid').value = DB[idx][4];
document.getElementById('search').value = ''; document.getElementById('search').value = '';
document.getElementById('page').value = null; document.getElementById('page').value = null;
@@ -169,21 +173,27 @@ function urlsToImgs(list) {
return rv + '</div>'; return rv + '</div>';
} }
function randomIPA() { function randomIPA(specificId) {
if (isInitial || saveConfig()) { if (saveConfig() || isInitial || specificId) {
applySearch(); applySearch();
} }
var idx = 0; var idx = specificId;
if (DB_result.length > 0) { if (!specificId) {
idx = DB_result[Math.floor(Math.random() * DB_result.length)]; if (DB_result.length > 0) {
} else { idx = DB_result[Math.floor(Math.random() * DB_result.length)];
idx = Math.floor(Math.random() * DB.length); } else {
idx = Math.floor(Math.random() * DB.length);
}
} }
const entry = entryToDict(DB[idx]); const entry = entryToDict(DB[idx]);
const output = document.getElementById('content'); const output = document.getElementById('content');
output.innerHTML = entriesToStr('.single', [idx]); output.innerHTML = entriesToStr('.full', [idx]);
output.firstElementChild.className += ' single';
output.firstElementChild.innerHTML += renderTemplate(getTemplate('.randomAllVer'), { $IDX: idx });
const iTunesUrl = 'http://itunes.apple.com/lookup?bundleId=' + entry.bundleId; return;
// Append iTunes info to result
const iTunesUrl = 'https://itunes.apple.com/lookup?bundleId=' + entry.bundleId;
loadFile(iTunesUrl, console.error, function (data) { loadFile(iTunesUrl, console.error, function (data) {
const obj = JSON.parse(data); const obj = JSON.parse(data);
if (!obj || obj.resultCount < 1) { if (!obj || obj.resultCount < 1) {