Skip to content

Commit b04e766

Browse files
committed
refactor: improve function naming
1 parent bd3db77 commit b04e766

2 files changed

Lines changed: 26 additions & 30 deletions

File tree

static/assets/js/launcher.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ function handleAppClick(app) {
5050
} else if (app.blank) {
5151
blank(selectedUrl, proxy);
5252
} else if (app.now) {
53-
now(selectedUrl, proxy);
53+
blank(selectedUrl, proxy);
5454
if (isInTabMode) window.location.href = selectedUrl;
5555
} else if (app.custom) {
5656
createCustomApp();
5757
} else if (app.dy) {
58-
dy(selectedUrl);
58+
useDynamic(selectedUrl);
5959
} else {
6060
go(selectedUrl, proxy);
6161
if (isInTabMode) blank(selectedUrl, proxy);
@@ -355,4 +355,4 @@ window.bar = filterBySearchTerm;
355355

356356
document.addEventListener("DOMContentLoaded", () => {
357357
loadAppsFromJson();
358-
});
358+
});

static/assets/js/search.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ if (form && input) {
1212
event.preventDefault();
1313
try {
1414
// isInTabMode is declared in main.js
15-
if (isInTabMode) await processUrl(input.value, "");
16-
else await processUrl(input.value, "/tabs");
15+
if (isInTabMode) await navigate(input.value, "");
16+
else await navigate(input.value, "/tabs");
1717
} catch {
18-
await processUrl(input.value, "/tabs");
18+
await navigate(input.value, "/tabs");
1919
}
2020
});
2121
}
22-
function useScramjetPxy(proxyOverride) {
23-
const p = proxyOverride ?? localStorage.getItem("pchoice");
24-
return p === "sj";
22+
23+
function isScramjet(proxyOverride) {
24+
const choice = proxyOverride ?? localStorage.getItem("pchoice");
25+
return choice === "sj";
2526
}
2627

27-
async function getPxyUrl(url, proxyOverride) {
28-
if (useScramjetPxy(proxyOverride)) {
28+
async function encodeUrl(url, proxyOverride) {
29+
if (isScramjet(proxyOverride)) {
2930
if (window.__isSjReady) {
3031
await window.__isSjReady;
3132
}
@@ -37,49 +38,44 @@ async function getPxyUrl(url, proxyOverride) {
3738
return `/uv/${__uv$config.encodeUrl(url)}`;
3839
}
3940

40-
async function processUrl(value, path, proxyOverride) {
41+
async function navigate(value, path, proxyOverride) {
4142
let url = value.trim();
4243
const engine = localStorage.getItem("engine");
4344
const searchUrl = engine ? engine : "https://search.brave.com/search?q=";
4445

45-
if (!isUrl(url)) {
46+
if (!isValidUrl(url)) {
4647
url = searchUrl + url;
4748
} else if (!(url.startsWith("https://") || url.startsWith("http://"))) {
4849
url = `https://${url}`;
4950
}
5051

5152
const pchoice = proxyOverride ?? localStorage.getItem("pchoice");
52-
const pxyUrl = await getPxyUrl(url, pchoice);
53-
sessionStorage.setItem("GoUrl", pxyUrl);
53+
const proxyUrl = await encodeUrl(url, pchoice);
54+
sessionStorage.setItem("GoUrl", proxyUrl);
5455

5556
if (pchoice === "dy") {
5657
window.location.href = `/uv/dynamic/${__uv$config.encodeUrl(url)}`;
5758
} else if (path) {
5859
location.href = path;
5960
} else {
60-
window.location.href = pxyUrl;
61+
window.location.href = proxyUrl;
6162
}
6263
}
6364

65+
// Open link in the tabs page
6466
function go(value, proxyOverride) {
65-
processUrl(value, "/tabs", proxyOverride);
67+
navigate(value, "/tabs", proxyOverride);
6668
}
6769

70+
// Open link in about:blank
6871
function blank(value, proxyOverride) {
69-
processUrl(value, "", proxyOverride);
70-
}
71-
72-
function now(value, proxyOverride) {
73-
processUrl(value, "", proxyOverride);
72+
navigate(value, "", proxyOverride);
7473
}
7574

76-
function dy(value) {
77-
processUrl(value, `/uv/dynamic/${__uv$config.encodeUrl(value)}`, "dy");
75+
function useDynamic(value) {
76+
navigate(value, `/uv/dynamic/${__uv$config.encodeUrl(value)}`, "dy");
7877
}
7978

80-
function isUrl(val = "") {
81-
if (/^http(s?):\/\//.test(val) || (val.includes(".") && val.substr(0, 1) !== " ")) {
82-
return true;
83-
}
84-
return false;
85-
}
79+
function isValidUrl(val = "") {
80+
return /^http(s?):\/\//.test(val) || (val.includes(".") && val[0] !== " ");
81+
}

0 commit comments

Comments
 (0)