remove unnecessary splitUrl helper function
This commit is contained in:
+5
-18
@@ -333,10 +333,9 @@
|
|||||||
|
|
||||||
static #formatSearchUrl(searchTemplate, query, commandUrl) {
|
static #formatSearchUrl(searchTemplate, query, commandUrl) {
|
||||||
if (!searchTemplate) return commandUrl;
|
if (!searchTemplate) return commandUrl;
|
||||||
const [commandBase] = Search.#splitUrl(commandUrl);
|
const { origin: commandOrigin } = new URL(searchTemplate, commandUrl);
|
||||||
const [searchBase, path] = Search.#splitUrl(searchTemplate);
|
const { href } = new URL(searchTemplate, commandOrigin);
|
||||||
const base = searchBase ?? commandBase;
|
return href.replace(/{}/g, encodeURIComponent(query));
|
||||||
return `${base}${path}`.replace(/{}/g, encodeURIComponent(query));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static #hasProtocol(s) {
|
static #hasProtocol(s) {
|
||||||
@@ -375,26 +374,14 @@
|
|||||||
|
|
||||||
if (COMMANDS.has(pathKey)) {
|
if (COMMANDS.has(pathKey)) {
|
||||||
const { url: base } = COMMANDS.get(pathKey);
|
const { url: base } = COMMANDS.get(pathKey);
|
||||||
const [baseUrl] = Search.#splitUrl(base);
|
const { origin } = new URL(base);
|
||||||
const url = `${baseUrl}/${path}`;
|
return { key: pathKey, path, query, splitBy, url: `${origin}/${path}` };
|
||||||
return { key: pathKey, path, query, splitBy, url };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = Search.#formatSearchUrl(CONFIG.defaultSearchTemplate, query);
|
const url = Search.#formatSearchUrl(CONFIG.defaultSearchTemplate, query);
|
||||||
return { query, search: query, url };
|
return { query, search: query, url };
|
||||||
};
|
};
|
||||||
|
|
||||||
static #splitUrl(url) {
|
|
||||||
try {
|
|
||||||
const u = new URL(url);
|
|
||||||
const base = `${u.protocol}//${u.hostname}`;
|
|
||||||
const rest = decodeURIComponent(`${u.pathname}${u.search}${u.hash}`);
|
|
||||||
return [base, rest];
|
|
||||||
} catch (e) {
|
|
||||||
return [null, url];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
this.#input.value = '';
|
this.#input.value = '';
|
||||||
this.#input.blur();
|
this.#input.blur();
|
||||||
|
|||||||
Reference in New Issue
Block a user