From 14bb2ca40103af307591e4336ae8331bd98f9103 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 28 Feb 2024 19:44:01 +0100 Subject: [PATCH] feat: random IPA mode --- index.html | 31 +++++++++++++++++++++++ script.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++------- style.css | 23 +++++++++++++++++ 3 files changed, 119 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 3f4a0799..bfb12c6c 100644 --- a/index.html +++ b/index.html @@ -28,8 +28,11 @@ + +
JavaScript disabled?
+ + + diff --git a/script.js b/script.js index 4d466c61..3236454d 100644 --- a/script.js +++ b/script.js @@ -94,7 +94,6 @@ function applySearch() { const minV = minos ? strToVersion(minos) : 0; const maxV = maxos ? strToVersion(maxos) : 9999999; const device = platform ? 1 << platform : 255; // all flags - const lenBundle = bundle.length; // [7, 2,20200,"180","com.headcasegames.180","1.0",1,"180.ipa", 189930], // [pk, platform, minOS, title, bundleId, version, baseUrl, pathName, size] @@ -153,6 +152,57 @@ function searchIPA(restorePage) { saveConfig(); } +/* + * Random IPA + */ + +function urlsToImgs(list) { + var rv = ''; +} + +function randomIPA() { + const idx = DB_result[Math.floor(Math.random() * DB_result.length)]; + const entry = entryToDict(DB[idx]); + const output = document.getElementById('content'); + output.innerHTML = entriesToStr('.single', [idx]); + + const iTunesUrl = 'http://itunes.apple.com/lookup?bundleId=' + entry.bundleId; + loadFile(iTunesUrl, setMessage, function (data) { + const obj = JSON.parse(data); + console.log(obj); + if (!obj || obj.resultCount < 1) { + return; + } + const info = obj.results[0]; + const imgs1 = info.screenshotUrls; + const imgs2 = info.ipadScreenshotUrls; + + var imgStr = ''; + if (imgs1 && imgs1.length > 0) { + imgStr += '

iPhone Screenshots:

' + urlsToImgs(imgs1); + } + if (imgs2 && imgs2.length > 0) { + imgStr += '

iPad Screenshots:

' + urlsToImgs(imgs2); + } + + output.innerHTML += getTemplate('.itunes') + .replace('$VERSION', info.version) + .replace('$PRICE', info.formattedPrice) + .replace('$RATING', info.averageUserRating.toFixed(1)) + .replace('$ADVISORY', info.contentAdvisoryRating) + .replace('$DATE', info.currentVersionReleaseDate) + .replace('$GENRES', (info.genres || []).join(', ')) + .replace('$URL', info.trackViewUrl) + .replace('$IMG', imgStr) + .replace('$DESCRIPTION', info.description); + }); +} + /* * Output */ @@ -189,11 +239,15 @@ function humanSize(size) { return size.toFixed(1) + ['kB', 'MB', 'GB'][sizeIndex]; } +function getTemplate(name) { + return document.getElementById('templates').querySelector(name).outerHTML; +} + function validUrl(url) { return encodeURI(url).replace('#', '%23').replace('?', '%3F'); } -function entriesToDict(entry) { +function entryToDict(entry) { const pk = entry[0]; return { pk: pk, @@ -210,12 +264,11 @@ function entriesToDict(entry) { } } -function entriesToStr(data) { - const templateType = document.getElementById('unique').checked ? '.short' : '.entry'; - const template = document.getElementById('templates').querySelector(templateType).outerHTML; +function entriesToStr(templateType, data) { + const template = getTemplate(templateType); var rv = ''; for (var i = 0; i < data.length; i++) { - const entry = entriesToDict(DB[data[i]]); + const entry = entryToDict(DB[data[i]]); rv += template .replace('$IDX', data[i]) .replace('$IMG', entry.img_url) @@ -245,7 +298,10 @@ function printIPA(offset) { if (pages > 1) { content += paginationShort(page, pages); } - content += entriesToStr(DB_result.slice(offset, offset + PER_PAGE)); + + const templateType = document.getElementById('unique').checked ? '.short' : '.entry'; + content += entriesToStr(templateType, DB_result.slice(offset, offset + PER_PAGE)); + if (pages > 1) { content += paginationShort(page, pages); content += paginationFull(page, pages); @@ -313,7 +369,7 @@ function urlWithSlash(url) { function utoa(data) { return btoa(unescape(encodeURIComponent(data))); - } +} function installIpa(idx) { if (!plistGeneratorUrl) { @@ -321,7 +377,7 @@ function installIpa(idx) { return; } const thisServerUrl = location.href.replace(location.hash, ''); - const entry = entriesToDict(DB[idx]); + const entry = entryToDict(DB[idx]); const json = JSON.stringify({ u: validUrl(entry.ipa_url), n: entry.title, diff --git a/style.css b/style.css index 28cc5509..331e0671 100644 --- a/style.css +++ b/style.css @@ -70,6 +70,29 @@ h4 { margin: 0 auto; } +/* Single-item page */ +.single { + display: block; + width: unset; +} +.itunes { + max-width: 600px; + margin: 40px auto; +} +.carousel { + display: block; + overflow: auto; + max-height: 350px; + white-space: nowrap; +} +.carousel img { + max-height: 330px; + margin: 8px; +} +.itunes p { + white-space: break-spaces; +} + /* Pagination */ .shortpage { text-align: center;