web: more ipad accommodations and clean up

- moved all user agent toggles to (legacy) frontend, like it should have always been
- removed unnecessary building
This commit is contained in:
wukko 2024-05-11 01:05:24 +06:00
parent 0e6ea09b16
commit e2d1913043
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
5 changed files with 24 additions and 35 deletions

View file

@ -1,4 +1,4 @@
import { genericUserAgent, version, env } from "../modules/config.js"; import { version, env } from "../modules/config.js";
import { apiJSON, languageCode } from "../modules/sub/utils.js"; import { apiJSON, languageCode } from "../modules/sub/utils.js";
import { Bright, Cyan } from "../modules/sub/consoleText.js"; import { Bright, Cyan } from "../modules/sub/consoleText.js";
@ -67,7 +67,7 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) {
return res.status(200).end() return res.status(200).end()
}); });
app.get("/", (req, res) => { app.get("/", (req, res) => {
return res.sendFile(`${__dirname}/${findRendered(languageCode(req), req.header('user-agent') ? req.header('user-agent') : genericUserAgent)}`) return res.sendFile(`${__dirname}/${findRendered(languageCode(req))}`)
}); });
app.get("/favicon.ico", (req, res) => { app.get("/favicon.ico", (req, res) => {
return res.sendFile(`${__dirname}/src/front/icons/favicon.ico`) return res.sendFile(`${__dirname}/src/front/icons/favicon.ico`)

View file

@ -1,6 +1,6 @@
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0); const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
const isMobile = ua.includes("android") || ua.includes("iphone os"); const isMobile = ua.includes("android") || isIOS;
const isSafari = ua.includes("safari/"); const isSafari = ua.includes("safari/");
const isFirefox = ua.includes("firefox/"); const isFirefox = ua.includes("firefox/");
const isOldFirefox = ua.includes("firefox/") && ua.split("firefox/")[1].split('.')[0] < 103; const isOldFirefox = ua.includes("firefox/") && ua.split("firefox/")[1].split('.')[0] < 103;
@ -576,6 +576,14 @@ const loadSettings = () => {
if (sGet("disableAnimations") === "true") { if (sGet("disableAnimations") === "true") {
eid("cobalt-body").classList.add('no-animation'); eid("cobalt-body").classList.add('no-animation');
} }
if (!isMobile) {
eid("cobalt-body").classList.add('desktop');
}
if (isIOS) {
eid("download-switcher")
.querySelector(".explanation")
.innerHTML = loc.DownloadPopupDescriptionIOS;
}
for (let i = 0; i < checkboxes.length; i++) { for (let i = 0; i < checkboxes.length; i++) {
try { try {
if (sGet(checkboxes[i]) === "true") eid(checkboxes[i]).checked = true; if (sGet(checkboxes[i]) === "true") eid(checkboxes[i]).checked = true;

View file

@ -13,9 +13,6 @@ export async function buildFront(commitHash, branch) {
// build html // build html
if (!fs.existsSync('./build/')){ if (!fs.existsSync('./build/')){
fs.mkdirSync('./build/'); fs.mkdirSync('./build/');
fs.mkdirSync('./build/ios/');
fs.mkdirSync('./build/pc/');
fs.mkdirSync('./build/mob/');
} }
// get rid of old build path // get rid of old build path
if (fs.existsSync('./min')) { if (fs.existsSync('./min')) {
@ -26,16 +23,9 @@ export async function buildFront(commitHash, branch) {
let params = { let params = {
"hash": commitHash, "hash": commitHash,
"lang": i, "lang": i,
"useragent": "pc",
"branch": branch "branch": branch
} }
fs.writeFileSync(`./build/pc/${i}.html`, cleanHTML(page(params))); fs.writeFileSync(`./build/${i}.html`, cleanHTML(page(params)));
params["useragent"] = "iphone os";
fs.writeFileSync(`./build/ios/${i}.html`, cleanHTML(page(params)));
params["useragent"] = "android";
fs.writeFileSync(`./build/mob/${i}.html`, cleanHTML(page(params)));
} }
// build js & css // build js & css
await esbuild.build({ await esbuild.build({
@ -45,7 +35,7 @@ export async function buildFront(commitHash, branch) {
loader: { '.js': 'js', '.css': 'css', }, loader: { '.js': 'js', '.css': 'css', },
charset: 'utf8' charset: 'utf8'
}) })
} catch (e) { } catch {
return; return;
} }
} }

View file

@ -1,11 +1,6 @@
import { languageList } from "../../localization/manager.js"; import { languageList } from "../../localization/manager.js";
export default function(lang, userAgent) { export default function(lang) {
let language = languageList.includes(lang) ? lang : "en"; let language = languageList.includes(lang) ? lang : "en";
return `/build/${language}.html`;
let ua = userAgent.toLowerCase();
let platform = (ua.match("android") || ua.match("iphone os")) ? "mob" : "pc";
if (platform === "mob" && ua.match("iphone os")) platform = "ios";
return `/build/${platform}/${language}.html`;
} }

View file

@ -47,14 +47,9 @@ for (let i in donations["crypto"]) {
} }
export default function(obj) { export default function(obj) {
const t = (str, replace) => { return loc(obj.lang, str, replace) }; const t = (str, replace) => {
return loc(obj.lang, str, replace)
let ua = obj.useragent.toLowerCase(); }
let isIOS = ua.match("iphone os");
let isMobile = ua.match("android") || ua.match("iphone os");
let platform = isMobile ? "m" : "d";
if (isMobile && isIOS) platform = "i";
audioFormats[0]["text"] = t('SettingsAudioFormatBest'); audioFormats[0]["text"] = t('SettingsAudioFormatBest');
@ -64,7 +59,7 @@ export default function(obj) {
<html lang="${obj.lang}"> <html lang="${obj.lang}">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="viewport-fit=cover, width=device-width, height=device-height, initial-scale=1, maximum-scale=${isIOS ? `1` : `5`}"> <meta name="viewport" content="viewport-fit=cover, width=device-width, height=device-height, initial-scale=1, maximum-scale=1">
<title>${t("AppTitleCobalt")}</title> <title>${t("AppTitleCobalt")}</title>
@ -103,7 +98,7 @@ export default function(obj) {
></script>` ></script>`
: ''} : ''}
</head> </head>
<body id="cobalt-body" ${platform === "d" ? 'class="desktop"' : ''}> <body id="cobalt-body">
<noscript> <noscript>
<div style="margin: 2rem;">${t('NoScriptMessage')}</div> <div style="margin: 2rem;">${t('NoScriptMessage')}</div>
</noscript> </noscript>
@ -314,7 +309,7 @@ export default function(obj) {
closeAria: t('AccessibilityGoBack'), closeAria: t('AccessibilityGoBack'),
header: { header: {
aboveTitle: { aboveTitle: {
text: `v.${version}-${obj.hash}${platform} (${obj.branch})`, text: `v.${version}-${obj.hash} (${obj.branch})`,
url: `${repo}/commit/${obj.hash}` url: `${repo}/commit/${obj.hash}`
}, },
title: `${emoji("⚙️", 30)} ${t('TitlePopupSettings')}` title: `${emoji("⚙️", 30)} ${t('TitlePopupSettings')}`
@ -562,7 +557,7 @@ export default function(obj) {
}, },
body: switcher({ body: switcher({
name: "download", name: "download",
explanation: `${!isIOS ? t('DownloadPopupDescription') : t('DownloadPopupDescriptionIOS')}`, explanation: t('DownloadPopupDescription'),
items: `<a id="pd-download" class="switch full" target="_blank" href="/"><span>${t('Download')}</span></a> items: `<a id="pd-download" class="switch full" target="_blank" href="/"><span>${t('Download')}</span></a>
<div id="pd-share" class="switch full">${t('ShareURL')}</div> <div id="pd-share" class="switch full">${t('ShareURL')}</div>
<div id="pd-copy" class="switch full">${t('CopyURL')}</div>` <div id="pd-copy" class="switch full">${t('CopyURL')}</div>`
@ -656,7 +651,8 @@ export default function(obj) {
'DataTransferError', 'DataTransferError',
'FilenamePreviewVideoTitle', 'FilenamePreviewVideoTitle',
'FilenamePreviewAudioTitle', 'FilenamePreviewAudioTitle',
'FilenamePreviewAudioAuthor' 'FilenamePreviewAudioAuthor',
'DownloadPopupDescriptionIOS'
])} ])}
</script> </script>
<script src="cobalt.js"></script> <script src="cobalt.js"></script>