From 5530ef6661f86d8d1a360589dc744c70110eb919 Mon Sep 17 00:00:00 2001 From: Spax <83354374+SpiritAxolotl@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:21:46 -0700 Subject: [PATCH] minor formatting overhaul (semicolons, removal of curly brackets, etc) --- .github/workflows/docker.yml | 2 +- src/cobalt.js | 6 +- src/core/api.js | 22 +- src/core/web.js | 31 ++- src/front/cobalt.css | 8 +- src/front/cobalt.js | 227 ++++++++---------- src/localization/manager.js | 14 +- src/modules/api.js | 4 +- src/modules/build.js | 2 +- src/modules/config.js | 6 +- src/modules/emoji.js | 2 +- src/modules/pageRender/elements.js | 99 ++++---- src/modules/pageRender/onDemand.js | 6 +- src/modules/pageRender/page.js | 29 ++- src/modules/processing/matchActionDecider.js | 8 +- src/modules/processing/services/bilibili.js | 4 +- src/modules/processing/services/instagram.js | 2 +- src/modules/processing/services/reddit.js | 2 +- src/modules/processing/services/rutube.js | 2 +- src/modules/processing/services/soundcloud.js | 8 +- src/modules/processing/services/youtube.js | 6 +- .../processing/servicesPatternTesters.js | 6 +- src/modules/setup.js | 27 +-- src/test/test.js | 2 +- 24 files changed, 248 insertions(+), 277 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8b7042d9..9326e9a2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -21,7 +21,7 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - + - name: Log in to the Container registry uses: docker/login-action@v2 with: diff --git a/src/cobalt.js b/src/cobalt.js index 2d90e07e..0df07670 100644 --- a/src/cobalt.js +++ b/src/cobalt.js @@ -26,14 +26,14 @@ const webMode = process.env.webURL && process.env.apiURL; if (apiMode) { const { runAPI } = await import('./core/api.js'); - runAPI(express, app, gitCommit, gitBranch, __dirname) + runAPI(express, app, gitCommit, gitBranch, __dirname); } else if (webMode) { const { runWeb } = await import('./core/web.js'); - await runWeb(express, app, gitCommit, gitBranch, __dirname) + await runWeb(express, app, gitCommit, gitBranch, __dirname); } else { console.log( Red(`cobalt wasn't configured yet or configuration is invalid.\n`) + Bright(`please run the setup script to fix this: `) + Green(`npm run setup`) - ) + ); } diff --git a/src/core/api.js b/src/core/api.js index 4ec36c34..a926eb3f 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -45,7 +45,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { }); } }); - + const startTime = new Date(); const startTimestamp = Math.floor(startTime.getTime()); @@ -95,10 +95,10 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { let request = req.body; if (contentCon && request.url) { request.dubLang = request.dubLang ? lang : false; - + let chck = checkJSONPost(request); if (!chck) throw new Error(); - + j = await getJSON(chck.url, lang, chck); } else { j = apiJSON(0, { @@ -119,7 +119,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { switch (req.params.type) { case 'stream': if (req.query.t && req.query.h && req.query.e && req.query.t.toString().length === 21 - && req.query.h.toString().length === 64 && req.query.e.toString().length === 13) { + && req.query.h.toString().length === 64 && req.query.e.toString().length === 13) { let streamInfo = verifyStream(req.query.t, req.query.h, req.query.e); if (streamInfo.error) { return res.status(streamInfo.status).json(apiJSON(0, { t: streamInfo.error }).body); @@ -132,8 +132,8 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { return stream(res, streamInfo); } else { let j = apiJSON(0, { - t: "stream token, hmac, or expiry timestamp is missing" - }) + t: "stream token, hmac, or expiry timestamp is missing", + }); return res.status(j.status).json(j.body); } case 'serverInfo': @@ -149,7 +149,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { default: let j = apiJSON(0, { t: "unknown response type" - }) + }); return res.status(j.status).json(j.body); } } catch (e) { @@ -160,13 +160,13 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { } }); app.get('/api/status', (req, res) => { - res.status(200).end() + res.status(200).end(); }); app.get('/favicon.ico', (req, res) => { - res.sendFile(`${__dirname}/src/front/icons/favicon.ico`) + res.sendFile(`${__dirname}/src/front/icons/favicon.ico`); }); app.get('/*', (req, res) => { - res.redirect('/api/json') + res.redirect('/api/json'); }); app.listen(process.env.apiPort || 9000, () => { @@ -175,6 +175,6 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { `Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` + `URL: ${Cyan(`${process.env.apiURL}`)}\n` + `Port: ${process.env.apiPort || 9000}\n` - ) + ); }); } diff --git a/src/core/web.js b/src/core/web.js index 08a6ffed..79d31471 100644 --- a/src/core/web.js +++ b/src/core/web.js @@ -31,49 +31,48 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) { case "0": r = changelogHistory(); j = r ? apiJSON(3, { t: r }) : apiJSON(0, { - t: "couldn't render this block, please try again!" - }) + t: "couldn't render this block, please try again!", + }); break; // celebrations emoji case "1": r = celebrationsEmoji(); - j = r ? apiJSON(3, { t: r }) : false + j = r ? apiJSON(3, { t: r }) : false; break; default: j = apiJSON(0, { t: "couldn't find a block with this id" - }) + }); break; } - if (j.body) { + if (j.body) return res.status(j.status).json(j.body); - } else { + else return res.status(204).end(); - } } else { return res.status(400).json({ status: "error", - text: "couldn't render this block, please try again!" + text: "couldn't render this block, please try again!", }); } } catch (e) { return res.status(400).json({ status: "error", - text: "couldn't render this block, please try again!" - }) + text: "couldn't render this block, please try again!", + }); } }); app.get("/status", (req, res) => { - return res.status(200).end() + return res.status(200).end(); }); 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), req.header('user-agent') ? req.header('user-agent') : genericUserAgent)}`); }); app.get("/favicon.ico", (req, res) => { - return res.sendFile(`${__dirname}/src/front/icons/favicon.ico`) + return res.sendFile(`${__dirname}/src/front/icons/favicon.ico`); }); app.get("/*", (req, res) => { - return res.redirect('/') + return res.redirect('/'); }); app.listen(process.env.webPort || 9001, () => { @@ -82,6 +81,6 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) { `Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` + `URL: ${Cyan(`${process.env.webURL}`)}\n` + `Port: ${process.env.webPort || 9001}\n` - ) - }) + ); + }); } diff --git a/src/front/cobalt.css b/src/front/cobalt.css index ff4f50d6..204c6453 100644 --- a/src/front/cobalt.css +++ b/src/front/cobalt.css @@ -1018,7 +1018,7 @@ button:active, /* adapt the page according to screen size */ @media screen and (max-width: 1550px) { .popup.small { - width: 25% + width: 25%; } .popup { width: 40%; @@ -1026,7 +1026,7 @@ button:active, } @media screen and (max-width: 1440px) { .popup.small { - width: 30% + width: 30%; } .popup { width: 45%; @@ -1039,7 +1039,7 @@ button:active, } @media screen and (max-width: 1200px) { .popup.small { - width: 35% + width: 35%; } .popup { width: 55%; @@ -1047,7 +1047,7 @@ button:active, } @media screen and (max-width: 1025px) { .popup.small { - width: 40% + width: 40%; } .popup { width: 60%; diff --git a/src/front/cobalt.js b/src/front/cobalt.js index cdf143bc..129f271b 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -42,23 +42,23 @@ const pageQuery = new URLSearchParams(window.location.search); let store = {}; function fixApiUrl(url) { - return url.endsWith('/') ? url.slice(0, -1) : url + return url.endsWith('/') ? url.slice(0, -1) : url; } let apiURL = fixApiUrl(defaultApiUrl); function changeApi(url) { apiURL = fixApiUrl(url); - return true + return true; } function eid(id) { - return document.getElementById(id) + return document.getElementById(id); } function sGet(id) { - return localStorage.getItem(id) + return localStorage.getItem(id); } function sSet(id, value) { - localStorage.setItem(id, value) + localStorage.setItem(id, value); } function enable(id) { eid(id).dataset.enabled = "true"; @@ -75,40 +75,39 @@ function opposite(state) { function changeDownloadButton(action, text) { switch (action) { case 0: - eid("download-button").disabled = true + eid("download-button").disabled = true; if (sGet("alwaysVisibleButton") === "true") { - eid("download-button").value = text - eid("download-button").style.padding = '0 1rem' + eid("download-button").value = text; + eid("download-button").style.padding = '0 1rem'; } else { - eid("download-button").value = '' - eid("download-button").style.padding = '0' + eid("download-button").value = ''; + eid("download-button").style.padding = '0'; } break; case 1: - eid("download-button").disabled = false - eid("download-button").value = text - eid("download-button").style.padding = '0 1rem' + eid("download-button").disabled = false; + eid("download-button").value = text; + eid("download-button").style.padding = '0 1rem'; break; case 2: - eid("download-button").disabled = true - eid("download-button").value = text - eid("download-button").style.padding = '0 1rem' + eid("download-button").disabled = true; + eid("download-button").value = text; + eid("download-button").style.padding = '0 1rem'; break; } } document.addEventListener("keydown", (event) => { if (event.key === "Tab") { - eid("download-button").value = '>>' - eid("download-button").style.padding = '0 1rem' + eid("download-button").value = '>>'; + eid("download-button").style.padding = '0 1rem'; } -}) +}); function button() { let regexTest = regex.test(eid("url-input-area").value); - if ((eid("url-input-area").value).length > 0) { + if ((eid("url-input-area").value).length > 0) eid("url-clear").style.display = "block"; - } else { + else eid("url-clear").style.display = "none"; - } regexTest ? changeDownloadButton(1, '>>') : changeDownloadButton(0, '>>'); } function clearInput() { @@ -127,35 +126,32 @@ async function share(url) { function detectColorScheme() { let theme = "auto"; let localTheme = sGet("theme"); - if (localTheme) { + if (localTheme) theme = localTheme; - } else if (!window.matchMedia) { - theme = "dark" - } + else if (!window.matchMedia) + theme = "dark"; document.documentElement.setAttribute("data-theme", theme); } -function changeTab(evnt, tabId, tabClass) { +function changeTab(event, tabId, tabClass) { if (tabId === "tab-settings-other") updateFilenamePreview(); let tabcontent = document.getElementsByClassName(`tab-content-${tabClass}`); let tablinks = document.getElementsByClassName(`tab-${tabClass}`); - for (let i = 0; i < tabcontent.length; i++) { + for (let i = 0; i < tabcontent.length; i++) tabcontent[i].dataset.enabled = "false"; - } - for (let i = 0; i < tablinks.length; i++) { + for (let i = 0; i < tablinks.length; i++) tablinks[i].dataset.enabled = "false"; - } - - evnt.currentTarget.dataset.enabled = "true"; + + event.currentTarget.dataset.enabled = "true"; eid(tabId).dataset.enabled = "true"; eid(tabId).parentElement.scrollTop = 0; if (tabId === "tab-about-changelog" && sGet("changelogStatus") !== `${version}`) notificationCheck("changelog"); if (tabId === "tab-about-about" && !sGet("seenAbout")) notificationCheck("about"); } -function expandCollapsible(evnt) { - let classlist = evnt.currentTarget.parentNode.classList; +function expandCollapsible(event) { + let classlist = event.currentTarget.parentNode.classList; let c = "expanded"; !classlist.contains(c) ? classlist.add(c) : classlist.remove(c); } @@ -166,7 +162,7 @@ function notificationCheck(type) { sSet("seenAbout", "true"); break; case "changelog": - sSet("changelogStatus", version) + sSet("changelogStatus", version); break; default: changed = false; @@ -174,8 +170,8 @@ function notificationCheck(type) { if (changed && sGet("changelogStatus") === `${version}` || type === "disable") { setTimeout(() => { eid("about-footer").innerHTML = eid("about-footer").innerHTML.replace(notification, ''); - eid("tab-button-about-changelog").innerHTML = eid("tab-button-about-changelog").innerHTML.replace(notification, '') - }, 900) + eid("tab-button-about-changelog").innerHTML = eid("tab-button-about-changelog").innerHTML.replace(notification, ''); + }, 900); } if (sGet("disableChangelog") !== "true") { if (!sGet("seenAbout") && !eid("about-footer").innerHTML.includes(notification)) eid("about-footer").innerHTML = `${notification}${eid("about-footer").innerHTML}`; @@ -187,9 +183,8 @@ function notificationCheck(type) { } function hideAllPopups() { let filter = document.getElementsByClassName('popup'); - for (let i = 0; i < filter.length; i++) { + for (let i = 0; i < filter.length; i++) filter[i].classList.remove("visible"); - } eid("popup-backdrop").classList.remove("visible"); store.isPopupOpen = false; @@ -237,7 +232,7 @@ function popup(type, action, text) { isIOS ? `onClick="share('${text.arr[i]["url"]}')"` : `href="${text.arr[i]["url"]}" target="_blank"` }>` + `` + - `` + ``; } break; default: @@ -247,11 +242,11 @@ function popup(type, action, text) { eid("picker-holder").innerHTML += `` + + }>` + `
${text.arr[i].type}
` + (text.arr[i].type === 'photo' ? '' : '
') + `` + - `
` + ``; } eid("picker-download").classList.remove("visible"); break; @@ -265,7 +260,7 @@ function popup(type, action, text) { if (type === "picker") { eid("picker-download").href = '/'; eid("picker-download").classList.remove("visible"); - eid("picker-holder").innerHTML = '' + eid("picker-holder").innerHTML = ''; } } if (bottomPopups.includes(type)) eid(`popup-${type}-container`).classList.toggle("visible"); @@ -277,18 +272,16 @@ function changeSwitcher(li, b) { if (b) { if (!switchers[li].includes(b)) b = switchers[li][0]; sSet(li, b); - for (let i in switchers[li]) { - (switchers[li][i] === b) ? enable(`${li}-${b}`) : disable(`${li}-${switchers[li][i]}`) - } + for (let i in switchers[li]) + (switchers[li][i] === b) ? enable(`${li}-${b}`) : disable(`${li}-${switchers[li][i]}`); if (li === "theme") detectColorScheme(); if (li === "filenamePattern") updateFilenamePreview(); } else { let pref = switchers[li][0]; if (isMobile && exceptions[li]) pref = exceptions[li]; sSet(li, pref); - for (let i in switchers[li]) { - (switchers[li][i] === pref) ? enable(`${li}-${pref}`) : disable(`${li}-${switchers[li][i]}`) - } + for (let i in switchers[li]) + (switchers[li][i] === pref) ? enable(`${li}-${pref}`) : disable(`${li}-${switchers[li][i]}`); } } function checkbox(action) { @@ -303,7 +296,7 @@ function checkbox(action) { function changeButton(type, text) { switch (type) { case 0: //error - eid("url-input-area").disabled = false + eid("url-input-area").disabled = false; eid("url-clear").style.display = "block"; changeDownloadButton(2, '!!'); popup("error", 1, text); @@ -312,18 +305,18 @@ function changeButton(type, text) { case 1: //enable back changeDownloadButton(1, '>>'); eid("url-clear").style.display = "block"; - eid("url-input-area").disabled = false + eid("url-input-area").disabled = false; break; case 2: //enable back + information popup popup("error", 1, text); changeDownloadButton(1, '>>'); eid("url-clear").style.display = "block"; - eid("url-input-area").disabled = false + eid("url-input-area").disabled = false; break; } } function internetError() { - eid("url-input-area").disabled = false + eid("url-input-area").disabled = false; changeDownloadButton(2, '!!'); setTimeout(() => { changeButton(1); }, 2500); popup("error", 1, loc.ErrorNoInternet); @@ -361,11 +354,10 @@ async function download(url) { filenamePattern: sGet("filenamePattern"), dubLang: false } - if (sGet("dubLang") === "auto") { - req.dubLang = true - } else if (sGet("dubLang") === "custom") { - req.dubLang = true - } + if (sGet("dubLang") === "auto") + req.dubLang = true; + else if (sGet("dubLang") === "custom") + req.dubLang = true; if (sGet("vimeoDash") === "true") req.vimeoDash = true; if (sGet("audioMode") === "true") { req.isAudioOnly = true; @@ -388,14 +380,14 @@ async function download(url) { }).then((r) => { return r.json() }).catch((e) => { return false }); if (!j) { internetError(); - return + return; } if (j && j.status !== "error" && j.status !== "rate-limit") { if (j.text && (!j.url || !j.picker)) { - if (j.status === "success") { - changeButton(2, j.text) - } else changeButton(0, loc.ErrorNoUrlReturned); + if (j.status === "success") + changeButton(2, j.text); + else changeButton(0, loc.ErrorNoUrlReturned); } switch (j.status) { case "redirect": @@ -412,27 +404,23 @@ async function download(url) { changeDownloadButton(2, '>>>'); popup('picker', 1, { arr: j.picker, type: j.pickerType }); setTimeout(() => { changeButton(1) }, 2500); - } else { - changeButton(0, loc.ErrorNoUrlReturned); - } + } else changeButton(0, loc.ErrorNoUrlReturned); break; case "stream": - changeDownloadButton(2, '?..') + changeDownloadButton(2, '?..'); fetch(`${j.url}&p=1`).then(async (res) => { let jp = await res.json(); if (jp.status === "continue") { changeDownloadButton(2, '>>>'); - if (sGet("downloadPopup") === "true") { - popup('download', 1, j.url) - } else { - if (isMobile || isSafari) { + if (sGet("downloadPopup") === "true") + popup('download', 1, j.url); + else { + if (isMobile || isSafari) window.location.href = j.url; - } else window.open(j.url, '_blank'); + else window.open(j.url, '_blank'); } setTimeout(() => { changeButton(1) }, 2500); - } else { - changeButton(0, jp.text); - } + } else changeButton(0, jp.text); }).catch((error) => internetError()); break; case "success": @@ -442,17 +430,14 @@ async function download(url) { changeButton(0, loc.ErrorUnknownStatus); break; } - } else if (j && j.text) { - changeButton(0, j.text); - } + } else if (j && j.text) changeButton(0, j.text); } async function loadCelebrationsEmoji() { let bac = eid("about-footer").innerHTML; try { let j = await fetch(`/onDemand?blockId=1`).then((r) => { if (r.status === 200) { return r.json() } else { return false } }).catch(() => { return false }); - if (j && j.status === "success" && j.text) { + if (j && j.status === "success" && j.text) eid("about-footer").innerHTML = eid("about-footer").innerHTML.replace('🐲', j.text); - } } catch (e) { eid("about-footer").innerHTML = bac; } @@ -463,9 +448,9 @@ async function loadOnDemand(elementId, blockId) { eid(elementId).innerHTML = `
...
`; try { - if (store.historyContent) { + if (store.historyContent) j = store.historyContent; - } else { + else { await fetch(`/onDemand?blockId=${blockId}`).then(async(r) => { j = await r.json(); if (j && j.status === "success") { @@ -473,12 +458,12 @@ async function loadOnDemand(elementId, blockId) { } else throw new Error(); }).catch(() => { throw new Error() }); } - if (j.text) { + if (j.text) eid(elementId).innerHTML = `${j.text}`; - } else throw new Error() + else throw new Error(); } catch (e) { eid(elementId).innerHTML = store.historyButton; - internetError() + internetError(); } } function restoreUpdateHistory() { @@ -491,20 +476,20 @@ function unpackSettings(b64) { let currentSettings = JSON.parse(JSON.stringify(localStorage)); for (let s in settingsToImport) { if (checkboxes.includes(s) && (settingsToImport[s] === "true" || settingsToImport[s] === "false") - && currentSettings[s] !== settingsToImport[s]) { + && currentSettings[s] !== settingsToImport[s]) { sSet(s, settingsToImport[s]); - changed = true + changed = true; } if (switchers[s] && switchers[s].includes(settingsToImport[s]) - && currentSettings[s] !== settingsToImport[s]) { + && currentSettings[s] !== settingsToImport[s]) { sSet(s, settingsToImport[s]); - changed = true + changed = true; } } } catch (e) { changed = false; } - return changed + return changed; } function updateFilenamePreview() { let videoFilePreview = ``; @@ -523,55 +508,50 @@ function updateFilenamePreview() { switch(sGet("filenamePattern")) { case "classic": videoFilePreview = `youtube_yPYZpwSpKmA_${resMatch[sGet('vQuality')]}_${sGet('vCodec')}` - + `${sGet("muteAudio") === "true" ? "_mute" : ""}.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; + + `${sGet("muteAudio") === "true" ? "_mute" : ""}.${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; audioFilePreview = `youtube_yPYZpwSpKmA_audio.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`; break; case "pretty": videoFilePreview = `${loc.FilenamePreviewVideoTitle} ` - + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, ` - + `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; + + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, ` + + `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor} (soundcloud).${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`; break; case "basic": videoFilePreview = `${loc.FilenamePreviewVideoTitle} ` - + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}${sGet("muteAudio") === "true" ? " mute" : ""}).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; + + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}${sGet("muteAudio") === "true" ? " mute" : ""}).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor}.${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`; break; case "nerdy": videoFilePreview = `${loc.FilenamePreviewVideoTitle} ` - + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, ` - + `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube, yPYZpwSpKmA).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; + + `(${sGet('vQuality') === "max" ? "2160p" : `${sGet('vQuality')}p`}, ${sGet('vCodec')}, ` + + `${sGet("muteAudio") === "true" ? "mute, " : ""}youtube, yPYZpwSpKmA).${sGet('vCodec') === "vp9" ? 'webm' : 'mp4'}`; audioFilePreview = `${loc.FilenamePreviewAudioTitle} - ${loc.FilenamePreviewAudioAuthor} (soundcloud, 1242868615).${sGet('aFormat') !== "best" ? sGet('aFormat') : 'opus'}`; break; } - eid("video-filename-text").innerHTML = videoFilePreview - eid("audio-filename-text").innerHTML = audioFilePreview + eid("video-filename-text").innerHTML = videoFilePreview; + eid("audio-filename-text").innerHTML = audioFilePreview; } function loadSettings() { if (sGet("alwaysVisibleButton") === "true") { eid("alwaysVisibleButton").checked = true; - eid("download-button").value = '>>' + eid("download-button").value = '>>'; eid("download-button").style.padding = '0 1rem'; } - if (sGet("downloadPopup") === "true" && !isIOS) { + if (sGet("downloadPopup") === "true" && !isIOS) eid("downloadPopup").checked = true; - } - if (sGet("reduceTransparency") === "true" || isOldFirefox) { + if (sGet("reduceTransparency") === "true" || isOldFirefox) eid("cobalt-body").classList.add('no-transparency'); - } - if (sGet("disableAnimations") === "true") { + if (sGet("disableAnimations") === "true") eid("cobalt-body").classList.add('no-animation'); - } - for (let i = 0; i < checkboxes.length; i++) { + for (let i = 0; i < checkboxes.length; i++) if (sGet(checkboxes[i]) === "true") eid(checkboxes[i]).checked = true; - } - for (let i in switchers) { - changeSwitcher(i, sGet(i)) - } - updateFilenamePreview() + for (let i in switchers) + changeSwitcher(i, sGet(i)); + updateFilenamePreview(); } window.onload = () => { loadCelebrationsEmoji(); @@ -587,22 +567,22 @@ window.onload = () => { eid("downloadPopup-chkbx").style.display = "none"; } - eid("home").style.visibility = 'visible'; + eid("home").style.visibility = "visible"; eid("home").classList.toggle("visible"); if (pageQuery.has("u") && regex.test(pageQuery.get("u"))) { eid("url-input-area").value = pageQuery.get("u"); - button() + button(); } if (pageQuery.has("migration")) { if (pageQuery.has("settingsData") && !sGet("migrated")) { let setUn = unpackSettings(pageQuery.get("settingsData")); if (setUn !== null) { if (setUn) { - sSet("migrated", "true") - eid("desc-migration").innerHTML += `

${loc.DataTransferSuccess}` + sSet("migrated", "true"); + eid("desc-migration").innerHTML += `

${loc.DataTransferSuccess}`; } else { - eid("desc-migration").innerHTML += `

${loc.DataTransferError}` + eid("desc-migration").innerHTML += `

${loc.DataTransferError}`; } } } @@ -615,16 +595,15 @@ window.onload = () => { notificationCheck(); // fix for animations not working in Safari - if (isIOS) { + if (isIOS) document.addEventListener('touchstart', () => {}, true); - } } eid("url-input-area").addEventListener("keydown", (e) => { button(); -}) +}); eid("url-input-area").addEventListener("keyup", (e) => { if (e.key === 'Enter') eid("download-button").click(); -}) +}); document.onkeydown = (e) => { if (!store.isPopupOpen) { if (e.metaKey || e.ctrlKey || e.key === "/") eid("url-input-area").focus(); @@ -636,13 +615,11 @@ document.onkeydown = (e) => { if (e.key === "D") pasteClipboard(); if (e.key === "K") changeSwitcher('audioMode', 'false'); if (e.key === "L") changeSwitcher('audioMode', 'true'); - + // popups if (e.key === "B") popup('about', 1, 'about'); // open about if (e.key === "N") popup('about', 1, 'changelog'); // open changelog if (e.key === "M") popup('settings', 1); - - } else { - if (e.key === "Escape") hideAllPopups(); - } + + } else if (e.key === "Escape") hideAllPopups(); } diff --git a/src/localization/manager.js b/src/localization/manager.js index 2b251fe3..1a342420 100644 --- a/src/localization/manager.js +++ b/src/localization/manager.js @@ -11,7 +11,7 @@ export async function loadLoc() { const files = await fs.promises.readdir(locPath).catch((e) => { return [] }); files.forEach(file => { loc[file.split('.')[0]] = loadJSON(`${locPath}/${file}`); - languages.push(file.split('.')[0]) + languages.push(file.split('.')[0]); }); } @@ -24,27 +24,27 @@ export function replaceBase(s) { .replace(/\*;/g, "•"); } export function replaceAll(lang, str, string, replacement) { - let s = replaceBase(str[string]) + let s = replaceBase(str[string]); if (replacement) s = s.replace(/{s}/g, replacement); if (s.match('{')) { Object.keys(loc[lang]["substrings"]).forEach(sub => { - s = replaceBase(s.replace(`{${sub}}`, loc[lang]["substrings"][sub])) + s = replaceBase(s.replace(`{${sub}}`, loc[lang]["substrings"][sub])); }); } - return s + return s; } export default function(lang, string, replacement) { try { if (!Object.keys(loc).includes(lang)) lang = 'en'; let str = loc[lang]["strings"]; if (str && str[string]) { - return replaceAll(lang, str, string, replacement) + return replaceAll(lang, str, string, replacement); } else { str = loc["en"]["strings"]; - return replaceAll(lang, str, string, replacement) + return replaceAll(lang, str, string, replacement); } } catch (e) { - return `!!${string}!!` + return `!!${string}!!`; } } export const languageList = languages; diff --git a/src/modules/api.js b/src/modules/api.js index c3549bb3..90cd79fe 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -26,8 +26,8 @@ export async function getJSON(url, lang, obj) { return apiJSON(0, { t: errorUnsupported(lang) }); } - return await match(host, patternMatch, url, lang, obj) + return await match(host, patternMatch, url, lang, obj); } catch (e) { - return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') }) + return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') }); } } diff --git a/src/modules/build.js b/src/modules/build.js index 887ffb50..143e1721 100644 --- a/src/modules/build.js +++ b/src/modules/build.js @@ -44,7 +44,7 @@ export async function buildFront(commitHash, branch) { minify: true, loader: { '.js': 'js', '.css': 'css', }, charset: 'utf8' - }) + }); } catch (e) { return; } diff --git a/src/modules/config.js b/src/modules/config.js index 5e079536..20e6da01 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -7,10 +7,10 @@ const servicesConfigJson = loadJSON("./src/modules/processing/servicesConfig.jso Object.values(servicesConfigJson.config).forEach(service => { service.patterns = service.patterns.map( pattern => new UrlPattern(pattern, { - segmentValueCharset: UrlPattern.defaultOptions.segmentValueCharset + '@\\.' + segmentValueCharset: UrlPattern.defaultOptions.segmentValueCharset + '@\\.', }) ) -}) +}); export const services = servicesConfigJson.config, @@ -26,4 +26,4 @@ export const supportedAudio = config.supportedAudio, celebrations = config.celebrations, links = config.links, - sponsors = config.sponsors + sponsors = config.sponsors; diff --git a/src/modules/emoji.js b/src/modules/emoji.js index f4793cb5..23e4aac5 100644 --- a/src/modules/emoji.js +++ b/src/modules/emoji.js @@ -62,5 +62,5 @@ export default function(emoji, size, disablePadding, fluent) { let filePath = `emoji/${names[emoji]}.svg`; if (fluent) filePath = `emoji/3d/${names[emoji]}.svg`; - return `` + return ``; } diff --git a/src/modules/pageRender/elements.js b/src/modules/pageRender/elements.js index a677d2bc..04435213 100644 --- a/src/modules/pageRender/elements.js +++ b/src/modules/pageRender/elements.js @@ -8,18 +8,20 @@ export const backButtonSVG = ` -` +`; -export const linkSVG = '' +export const linkSVG = ` + +`; export function switcher(obj) { let items = ``; - if (obj.name === "download") { + if (obj.name === "download") items = obj.items; - } else { + else { for (let i = 0; i < obj.items.length; i++) { let classes = obj.items[i]["classes"] ? obj.items[i]["classes"] : []; - items += `` + items += ``; } } @@ -28,7 +30,7 @@ export function switcher(obj) { ${obj.subtitle ? `
${obj.subtitle}
` : ``}
${items}
${obj.explanation ? `
${obj.explanation}
` : ``} - ` + `; } export function checkbox(obj) { let paddings = ["bottom-margin", "top-margin", "no-margin", "top-margin-only"]; @@ -39,14 +41,14 @@ export function checkbox(obj) { checkboxes += `` + `; } - return checkboxes + return checkboxes; } export function sep(paddingType) { - let paddingClass = `` + let paddingClass = ``; switch(paddingType) { - case 0: + case 0: paddingClass += ` top-margin`; break; } @@ -56,14 +58,13 @@ export function popup(obj) { let classes = obj.classes ? obj.classes : []; let body = obj.body; if (Array.isArray(obj.body)) { - body = `` + body = ``; for (let i = 0; i < obj.body.length; i++) { if (obj.body[i]["text"].length > 0) { - classes = obj.body[i]["classes"] ?? [] - if (i !== obj.body.length - 1 && !obj.body[i]["nopadding"]) { - classes.push("desc-padding") - } - body += obj.body[i]["raw"] ? obj.body[i]["text"] : `
${obj.body[i]["text"]}
` + classes = obj.body[i]["classes"] ?? []; + if (i !== obj.body.length - 1 && !obj.body[i]["nopadding"]) + classes.push("desc-padding"); + body += obj.body[i]["raw"] ? obj.body[i]["text"] : `
${obj.body[i]["text"]}
`; } } } @@ -82,7 +83,7 @@ export function popup(obj) { ${body}${obj.buttonOnly ? `` : ''} ${classes.includes("small") ? `
` : ''} - ${obj.standalone ? `` : ''}` + ${obj.standalone ? `` : ''}`; } export function multiPagePopup(obj) { @@ -93,8 +94,8 @@ export function multiPagePopup(obj) { let tabContent = ``; for (let i = 0; i < obj.tabs.length; i++) { - tabs += `` - tabContent += `` + tabs += ``; + tabContent += ``; } return ` @@ -112,7 +113,7 @@ export function multiPagePopup(obj) {
- ` + `; } export function collapsibleList(arr) { let items = ``; @@ -125,7 +126,7 @@ export function collapsibleList(arr) {
${dropdownSVG}
${arr[i]["body"]}
- ` + `; } return items; } @@ -133,11 +134,10 @@ export function popupWithBottomButtons(obj) { let tabs = ` ` + `; - for (let i = 0; i < obj.buttons.length; i++) { - tabs += obj.buttons[i] - } + for (let i = 0; i < obj.buttons.length; i++) + tabs += obj.buttons[i]; return ` ` + `; } export function socialLink(emji, name, url) { - return `` + return ``; } export function socialLinks(lang) { let links = authorInfo.support[lang] ? authorInfo.support[lang] : authorInfo.support.default; let r = ``; - for (let i in links) { + for (let i in links) r += socialLink( emoji(links[i].emoji), links[i].name, links[i].url - ) - } - return r + ); + return r; } export function settingsCategory(obj) { return `
${obj.title ?? obj.name}
${obj.body}
-
` + `; } export function footerButtons(obj) { - let items = `` + let items = ``; for (let i = 0; i < obj.length; i++) { let buttonName = obj[i]["context"] ? `${obj[i]["name"]}-${obj[i]["context"]}` : obj[i]["name"], context = obj[i]["context"] ? `, '${obj[i]["context"]}'` : '', @@ -196,11 +195,10 @@ export function footerButtons(obj) { `; i++; } - return ` - ` + return ``; } export function explanation(text) { - return `
${text}
` + return `
${text}
`; } export function celebrationsEmoji() { try { @@ -209,16 +207,16 @@ export function celebrationsEmoji() { let f = Object.keys(celebrations).includes(dm) ? celebrations[dm] : "🐲"; return f != "🐲" ? emoji(f, 22) : false; } catch (e) { - return false + return false; } } export function urgentNotice(obj) { if (obj.visible) { return `
` + `${emoji(obj.emoji, 18)} ${obj.text}` + - `
` + ``; } - return `` + return ``; } export function keyboardShortcuts(arr) { let base = `
`; @@ -228,10 +226,10 @@ export function keyboardShortcuts(arr) { for (let c = 0; c < arr[i].items.length; c++) { let combo = arr[i].items[c].combo.split('+').map( key => `${key}` - ).join("+") - base += `
${combo}: ${arr[i].items[c].name}
` + ).join("+"); + base += `
${combo}: ${arr[i].items[c].name}
`; } - base += `
` + base += ``; } base += ``; @@ -239,30 +237,29 @@ export function keyboardShortcuts(arr) { } export function webLoc(t, arr) { let base = ``; - for (let i = 0; i < arr.length; i++) { - base += `${arr[i]}:` + "`" + t(arr[i]) + "`" + `,` - } + for (let i = 0; i < arr.length; i++) + base += `${arr[i]}:` + "`" + t(arr[i]) + "`" + `,`; return `{${base}};` } export function sponsoredList() { let base = ``; - let altText = `` + let altText = ``; for (let i = 0; i < sponsors.length; i++) { let s = sponsors[i]; let loadedLogo = loadFile(`./src/front/sponsors/${s.name}.svg`); altText += `${s.fullName ? s.fullName : s.name}, `; base += - `` + `; } - return `` + return ``; } export function betaTag() { - return process.env.isBeta ? 'β' : '' + return process.env.isBeta ? 'β' : ''; } diff --git a/src/modules/pageRender/onDemand.js b/src/modules/pageRender/onDemand.js index 7667708f..f136686a 100644 --- a/src/modules/pageRender/onDemand.js +++ b/src/modules/pageRender/onDemand.js @@ -1,13 +1,13 @@ import changelogManager from "../changelog/changelogManager.js" import { cleanHTML } from "../sub/utils.js"; -let cache = {} +let cache = {}; export function changelogHistory() { // blockId 0 if (cache['0']) return cache['0']; let history = changelogManager("history"); let render = ``; - + let historyLen = history.length; for (let i in history) { let separator = (i !== 0 && i !== historyLen) ? '
' : ''; @@ -25,7 +25,7 @@ export function changelogHistory() { // blockId 0 ` : ''} - ` + `; } render = cleanHTML(render); cache['0'] = render; diff --git a/src/modules/pageRender/page.js b/src/modules/pageRender/page.js index 81e6d514..ad07b85e 100644 --- a/src/modules/pageRender/page.js +++ b/src/modules/pageRender/page.js @@ -8,22 +8,21 @@ import changelogManager from "../changelog/changelogManager.js"; let com = getCommitInfo(); let enabledServices = Object.keys(s).filter(p => s[p].enabled).sort().map((p) => { - return `
• ${s[p].alias ? s[p].alias : p}` -}).join('').substring(4) + return `
• ${s[p].alias ? s[p].alias : p}`; +}).join('').substring(4); -let donate = `` -let donateLinks = `` +let donate = ``; +let donateLinks = ``; let audioFormats = supportedAudio.map((p) => { - return { "action": p } + return { "action": p }; }) -audioFormats.unshift({ "action": "best" }) -for (let i in donations["links"]) { - donateLinks += `REPLACEME ${i}` -} -let extr = '' +audioFormats.unshift({ "action": "best" }); +for (let i in donations["links"]) + donateLinks += `REPLACEME ${i}`; +let extr = ''; for (let i in donations["crypto"]) { - donate += `
${i} (REPLACEME)
${donations["crypto"][i]}
` - extr = ' top-margin' + donate += `
${i} (REPLACEME)
${donations["crypto"][i]}
`; + extr = ' top-margin'; } export default function(obj) { @@ -56,7 +55,7 @@ export default function(obj) { - + @@ -107,7 +106,7 @@ export default function(obj) { }, { name: "keyboard", title: `${emoji("⌨")} ${t("CollapseKeyboard")}`, - body: + body: `${t("KeyboardShortcutsIntro")} ${keyboardShortcuts([{ items: [{ @@ -650,7 +649,7 @@ export default function(obj) { -` +`; } catch (err) { return `${t('ErrorPageRenderFail', obj.hash)}`; } diff --git a/src/modules/processing/matchActionDecider.js b/src/modules/processing/matchActionDecider.js index 7aa154bd..e41c5eed 100644 --- a/src/modules/processing/matchActionDecider.js +++ b/src/modules/processing/matchActionDecider.js @@ -40,7 +40,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di case "photo": responseType = 1; break; - + case "gif": params = { type: "gif" } break; @@ -100,7 +100,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di responseType = 1; } break; - + case "twitter": if (r.type === "remux") { params = { type: r.type }; @@ -125,14 +125,14 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di } break; - case "audio": + case "audio": if ((host === "reddit" && r.typeId === 1) || audioIgnore.includes(host)) { return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') }) } let processType = "render", copy = false; - + if (!supportedAudio.includes(audioFormat)) { audioFormat = "best" } diff --git a/src/modules/processing/services/bilibili.js b/src/modules/processing/services/bilibili.js index 0194ee46..8120a776 100644 --- a/src/modules/processing/services/bilibili.js +++ b/src/modules/processing/services/bilibili.js @@ -11,11 +11,11 @@ export default async function(obj) { let streamData = JSON.parse(html.split('')[0]); if (streamData.data.timelength > maxVideoDuration) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] }; - let video = streamData["data"]["dash"]["video"].filter(v => + let video = streamData["data"]["dash"]["video"].filter(v => !v["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/") ).sort((a, b) => Number(b.bandwidth) - Number(a.bandwidth)); - let audio = streamData["data"]["dash"]["audio"].filter(a => + let audio = streamData["data"]["dash"]["audio"].filter(a => !a["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/") ).sort((a, b) => Number(b.bandwidth) - Number(a.bandwidth)); diff --git a/src/modules/processing/services/instagram.js b/src/modules/processing/services/instagram.js index 8d8a11d7..362bb43b 100644 --- a/src/modules/processing/services/instagram.js +++ b/src/modules/processing/services/instagram.js @@ -120,7 +120,7 @@ async function getStory(username, id) { const item = media.items[media.media_ids.indexOf(id)]; if (!item) return { error: 'ErrorEmptyDownload' }; - + if (item.video_versions) { const video = item.video_versions.reduce((a, b) => a.width * a.height < b.width * b.height ? b : a) return { diff --git a/src/modules/processing/services/reddit.js b/src/modules/processing/services/reddit.js index 8964b24f..c3db8453 100644 --- a/src/modules/processing/services/reddit.js +++ b/src/modules/processing/services/reddit.js @@ -9,7 +9,7 @@ async function getAccessToken() { * you can get these by making a reddit app and * authenticating an account against reddit's oauth2 api * see: https://github.com/reddit-archive/reddit/wiki/OAuth2 - * + * * any additional cookie fields are managed by this code and you * should not touch them unless you know what you're doing. **/ const cookie = await getCookie('reddit'); diff --git a/src/modules/processing/services/rutube.js b/src/modules/processing/services/rutube.js index af99a31d..7aad1393 100644 --- a/src/modules/processing/services/rutube.js +++ b/src/modules/processing/services/rutube.js @@ -11,7 +11,7 @@ export default async function(obj) { if (!play.video_balancer || play.detail) return { error: 'ErrorEmptyDownload' }; if (play.duration > maxVideoDuration) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] }; - + let m3u8 = await fetch(play.video_balancer.m3u8).then((r) => { return r.text() }).catch(() => { return false }); if (!m3u8) return { error: 'ErrorCouldntFetch' }; diff --git a/src/modules/processing/services/soundcloud.js b/src/modules/processing/services/soundcloud.js index 46aae5df..96280ad2 100644 --- a/src/modules/processing/services/soundcloud.js +++ b/src/modules/processing/services/soundcloud.js @@ -9,17 +9,17 @@ async function findClientID() { let scVersion = String(sc.match(/