implemented search on youtube
This commit is contained in:
parent
21719a6cf7
commit
13fae1c23f
@ -55,8 +55,8 @@ air dev
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
- implement templating for every one of the frontend files
|
||||||
- implement functionality to clear and clean cache
|
- implement functionality to clear and clean cache
|
||||||
- implement fetching in intervals
|
|
||||||
- host this website on a demo page
|
- host this website on a demo page
|
||||||
- implement ctl
|
- implement ctl
|
||||||
- implement autocomplete with a nice go backend and fast communication. Since it all runs locally nobody should have privacy concerns NEEDS TO BE ABLE TO TOGGLED OFF FOR DEMO PAGE
|
- implement autocomplete with a nice go backend and fast communication. Since it all runs locally nobody should have privacy concerns NEEDS TO BE ABLE TO TOGGLED OFF FOR DEMO PAGE
|
||||||
|
@ -4,45 +4,49 @@ const form = document.getElementById("search-form");
|
|||||||
const input = document.getElementById("search-input");
|
const input = document.getElementById("search-input");
|
||||||
|
|
||||||
// https://stackoverflow.com/a/3809435/16804841
|
// https://stackoverflow.com/a/3809435/16804841
|
||||||
const expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
const expression =
|
||||||
|
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
||||||
const urlRegex = new RegExp(expression);
|
const urlRegex = new RegExp(expression);
|
||||||
|
|
||||||
const searchEngines = {
|
const searchEngines = {
|
||||||
"g": {
|
g: {
|
||||||
action: "https://www.google.com/search",
|
action: "https://www.google.com/search",
|
||||||
name: "q",
|
name: "q",
|
||||||
},
|
},
|
||||||
"d": {
|
d: {
|
||||||
action: "https://duckduckgo.com/",
|
action: "https://duckduckgo.com/",
|
||||||
name: "q",
|
name: "q",
|
||||||
},
|
},
|
||||||
"y": {
|
y: {
|
||||||
|
action: "https://www.youtube.com/results",
|
||||||
|
name: "search_query",
|
||||||
|
},
|
||||||
|
ya: {
|
||||||
action: "https://yandex.com/search/",
|
action: "https://yandex.com/search/",
|
||||||
name: "text",
|
name: "text",
|
||||||
},
|
},
|
||||||
"lure": {
|
lure: {
|
||||||
action: "https://lure.sh/pkgs",
|
action: "https://lure.sh/pkgs",
|
||||||
name: "q",
|
name: "q",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const translationPrefixes = [
|
const translationPrefixes = ["t", "translation"];
|
||||||
"t",
|
|
||||||
"translation",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
function getDeepLUrl(s) {
|
function getDeepLUrl(s) {
|
||||||
const parts = s.split("-")
|
const parts = s.split("-");
|
||||||
if (parts.length != 3) {
|
if (parts.length != 3) {
|
||||||
return undefined
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `https://www.deepl.com/en/translator?/#${encodeURIComponent(parts[0].trim())}/${encodeURIComponent(parts[1].trim())}/${encodeURIComponent(parts[2].trim())}`;
|
return `https://www.deepl.com/en/translator?/#${encodeURIComponent(
|
||||||
|
parts[0].trim()
|
||||||
|
)}/${encodeURIComponent(parts[1].trim())}/${encodeURIComponent(
|
||||||
|
parts[2].trim()
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.addEventListener("submit", (event) => {
|
||||||
form.addEventListener("submit", event => {
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
s = input.value;
|
s = input.value;
|
||||||
@ -50,7 +54,7 @@ form.addEventListener("submit", event => {
|
|||||||
// check if url
|
// check if url
|
||||||
if (s.match(urlRegex)) {
|
if (s.match(urlRegex)) {
|
||||||
window.open(s, "_self");
|
window.open(s, "_self");
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deepl translations
|
// deepl translations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user