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 +=
`` +
+ }>` +
`
` +
- ``
+ ``;
}
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 = `