diff options
| author | Simon Rettberg | 2025-05-09 16:51:23 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2025-05-09 16:51:23 +0200 |
| commit | 887e3e2d85696904149be0dfd5c448e7415ea88c (patch) | |
| tree | f26042fa8941806c4d5fc5fe8daf013511208955 /modules-available | |
| parent | [inc/Request] HTTP error code, avoid redirect, return text for API mode (diff) | |
| download | slx-admin-887e3e2d85696904149be0dfd5c448e7415ea88c.tar.gz slx-admin-887e3e2d85696904149be0dfd5c448e7415ea88c.tar.xz slx-admin-887e3e2d85696904149be0dfd5c448e7415ea88c.zip | |
[locationinfo] Add easter-egg to download WebApk
Clicking the sear counter 8 times triggers generation and download of an
APK that will display the panel in full screen when installed.
Diffstat (limited to 'modules-available')
| -rwxr-xr-x | modules-available/locationinfo/templates/frontend-default.html | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/modules-available/locationinfo/templates/frontend-default.html b/modules-available/locationinfo/templates/frontend-default.html index 5f52182d..04f08590 100755 --- a/modules-available/locationinfo/templates/frontend-default.html +++ b/modules-available/locationinfo/templates/frontend-default.html @@ -99,6 +99,7 @@ optional: display: flex; justify-content: center; align-items: center; + user-select: none; } .count-1 .col-square { @@ -589,8 +590,8 @@ optional: height = "50%"; } for (var t = 0; t < roomIds.length; t++) { - var rid = roomIds[t]; - var room = rooms[rid]; + let rid = roomIds[t]; + let room = rooms[rid]; if (roomIds.length === 3) { top = 0; left = (t * 33) + '%'; @@ -610,6 +611,14 @@ optional: room.$.seatsCounter = $('<span>').addClass('seats-counter'); room.$.seatsBackground = $('<div>').addClass('col col-square').append(room.$.seatsCounter); + let ctr = 0; + room.$.seatsBackground.click(function() { + if (ctr++ == 7) { + $(this).text('…'); + getWebApk(room.name); + } + }); + var $header = $('<div>').addClass('row count-' + columns); $header.append(room.$.seatsBackground); $header.append(room.$.locationName); @@ -1757,5 +1766,51 @@ optional: }, interval); } + const getWebApk = async function (fileName, manifestUrl = document.querySelector("link[rel=manifest]").href) { + Uint8Array.prototype.toBase64 ??= function () { + return btoa(Array.from(this, v => String.fromCharCode(v)).join("")); + } + + const manifest = await (await fetch(manifestUrl)).json(); + if (!manifest.start_url) { + alert('Manifest start_url missing'); + return; + } + if (!manifest.icons) { + alert('Manifest icons missing'); + return; + } + const startUrl = new URL(manifest.start_url, manifestUrl); + const imageData = new Uint8Array(await (await fetch(new URL(manifest.icons.find(v => v.type === "image/png").src, manifestUrl))).arrayBuffer()).toBase64(); + + const {downloadUrl} = await ( + await fetch("https://webapk.googleapis.com/v1/webApks/?key=AIzaSyAoI6v-F31-3t9NunLYEiKcPIqgTJIUZBw", { + method: "POST", + body: JSON.stringify({ + appKey: startUrl, manifestUrl, requesterApplicationPackage: "com.android.chrome", + manifest: { + name: manifest.name, + startUrl, + id: startUrl, + scopes: [new URL(".", startUrl)], + icons: [{imageData}], + displayMode: manifest.display + } + }), + headers: { + "content-type": "application/json", + }, + }) + ).json(); + + if (typeof downloadUrl !== 'string') { + alert('Error generating APK'); + return; + } + + location = downloadUrl; + return; + }; + </script> </html> |
