2024-06-14 17:48:57 +02:00
|
|
|
<script lang="ts">
|
2024-06-16 21:18:39 +02:00
|
|
|
import IconLink from "@tabler/icons-svelte/IconLink.svelte";
|
2024-06-14 17:48:57 +02:00
|
|
|
|
2024-06-16 11:30:14 +02:00
|
|
|
import DownloadButton from "./buttons/DownloadButton.svelte";
|
|
|
|
import ClearButton from "./buttons/ClearButton.svelte";
|
|
|
|
import ActionButton from "../buttons/ActionButton.svelte";
|
2024-06-15 16:39:34 +02:00
|
|
|
|
2024-06-16 11:30:14 +02:00
|
|
|
import Switcher from "../buttons/Switcher.svelte";
|
|
|
|
|
|
|
|
import IconSparkles from "$lib/icons/Sparkles.svelte";
|
|
|
|
import IconMusic from "$lib/icons/Music.svelte";
|
|
|
|
import IconMute from "$lib/icons/Mute.svelte";
|
|
|
|
|
|
|
|
import IconClipboard from "$lib/icons/Clipboard.svelte";
|
2024-06-14 17:48:57 +02:00
|
|
|
|
|
|
|
let link: string = "";
|
|
|
|
let isFocused = false;
|
|
|
|
|
|
|
|
const validLink = (link: string) => {
|
|
|
|
try {
|
|
|
|
return /^https:/i.test(new URL(link).protocol);
|
|
|
|
} catch {
|
2024-06-16 11:30:14 +02:00
|
|
|
return false;
|
2024-06-14 17:48:57 +02:00
|
|
|
}
|
2024-06-16 11:30:14 +02:00
|
|
|
};
|
2024-06-15 16:39:34 +02:00
|
|
|
|
|
|
|
const pasteClipboard = () => {
|
2024-06-16 11:30:14 +02:00
|
|
|
navigator.clipboard.readText().then((text) => {
|
2024-06-15 16:39:34 +02:00
|
|
|
let matchLink = text.match(/https:\/\/[^\s]+/g);
|
|
|
|
if (matchLink) {
|
|
|
|
link = matchLink[0];
|
|
|
|
}
|
|
|
|
});
|
2024-06-16 11:30:14 +02:00
|
|
|
};
|
2024-06-14 17:48:57 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div id="omnibox">
|
2024-06-16 11:30:14 +02:00
|
|
|
<div
|
|
|
|
id="input-container"
|
|
|
|
class:focused={isFocused}
|
|
|
|
class:downloadable={validLink(link)}
|
|
|
|
>
|
2024-06-14 17:48:57 +02:00
|
|
|
<IconLink id="input-link-icon" color="var(--gray)" size="18px" />
|
|
|
|
|
|
|
|
<input
|
|
|
|
id="link-area"
|
|
|
|
bind:value={link}
|
2024-06-16 11:30:14 +02:00
|
|
|
on:input={() => (isFocused = true)}
|
|
|
|
on:focus={() => (isFocused = true)}
|
|
|
|
on:blur={() => (isFocused = false)}
|
2024-06-14 17:48:57 +02:00
|
|
|
spellcheck="false"
|
|
|
|
autocomplete="off"
|
|
|
|
autocapitalize="off"
|
|
|
|
maxlength="256"
|
|
|
|
placeholder="paste the link here"
|
|
|
|
aria-label="link input area"
|
2024-06-16 17:54:02 +02:00
|
|
|
data-form-type="other"
|
2024-06-16 11:30:14 +02:00
|
|
|
/>
|
2024-06-14 17:48:57 +02:00
|
|
|
|
|
|
|
{#if link.length > 0}
|
2024-06-16 11:30:14 +02:00
|
|
|
<ClearButton click={() => (link = "")} />
|
2024-06-14 17:48:57 +02:00
|
|
|
{/if}
|
|
|
|
{#if validLink(link)}
|
2024-06-16 14:22:44 +02:00
|
|
|
<DownloadButton url={link} />
|
2024-06-14 17:48:57 +02:00
|
|
|
{/if}
|
|
|
|
</div>
|
2024-06-16 11:30:14 +02:00
|
|
|
|
2024-06-15 16:39:34 +02:00
|
|
|
<div id="action-container">
|
2024-06-16 11:30:14 +02:00
|
|
|
<Switcher settingId="save-downloadMode">
|
|
|
|
<ActionButton id="auto-mode-button" text="auto">
|
|
|
|
<IconSparkles />
|
2024-06-15 16:39:34 +02:00
|
|
|
</ActionButton>
|
2024-06-16 11:30:14 +02:00
|
|
|
<ActionButton id="audio-mode-button" text="audio">
|
2024-06-15 16:39:34 +02:00
|
|
|
<IconMusic />
|
|
|
|
</ActionButton>
|
2024-06-16 11:30:14 +02:00
|
|
|
<ActionButton id="mute-mode-button" text="mute">
|
|
|
|
<IconMute />
|
|
|
|
</ActionButton>
|
|
|
|
</Switcher>
|
|
|
|
<ActionButton id="paste-button" click={pasteClipboard} text="paste">
|
2024-06-15 16:39:34 +02:00
|
|
|
<IconClipboard />
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
2024-06-14 17:48:57 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#omnibox {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
max-width: 640px;
|
|
|
|
width: 100%;
|
|
|
|
gap: var(--padding);
|
|
|
|
}
|
|
|
|
|
|
|
|
#input-container {
|
|
|
|
display: flex;
|
2024-06-16 17:45:24 +02:00
|
|
|
box-shadow: 0 0 0 1.5px var(--input-border) inset;
|
2024-06-16 15:51:02 +02:00
|
|
|
border-radius: var(--border-radius);
|
2024-06-14 17:48:57 +02:00
|
|
|
padding: 0 12px;
|
|
|
|
align-items: center;
|
|
|
|
gap: 10px;
|
|
|
|
font-size: 14px;
|
2024-06-16 11:30:14 +02:00
|
|
|
flex: 1;
|
2024-06-14 17:48:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#input-container.downloadable {
|
|
|
|
padding-right: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#input-container.focused {
|
|
|
|
box-shadow: 0 0 0 1.5px var(--secondary) inset;
|
|
|
|
outline: var(--secondary) 0.5px solid;
|
|
|
|
}
|
|
|
|
|
|
|
|
#input-container.focused :global(#input-link-icon) {
|
|
|
|
stroke: var(--secondary);
|
|
|
|
}
|
2024-06-16 19:30:10 +02:00
|
|
|
|
2024-06-14 17:48:57 +02:00
|
|
|
#input-container.downloadable :global(#input-link-icon) {
|
|
|
|
stroke: var(--secondary);
|
|
|
|
}
|
|
|
|
|
|
|
|
#link-area {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
margin: 0;
|
|
|
|
padding: 12px 0;
|
|
|
|
height: 18px;
|
|
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
border: none;
|
|
|
|
outline: none;
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--secondary);
|
|
|
|
|
|
|
|
-webkit-tap-highlight-color: transparent;
|
|
|
|
flex: 1;
|
|
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
|
|
/* workaround for safari */
|
|
|
|
font-size: inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#link-area::placeholder {
|
2024-06-16 11:30:14 +02:00
|
|
|
color: var(--gray);
|
2024-06-14 17:48:57 +02:00
|
|
|
}
|
2024-06-15 16:39:34 +02:00
|
|
|
|
2024-06-16 11:30:14 +02:00
|
|
|
#action-container {
|
2024-06-15 16:39:34 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
2024-06-16 11:30:14 +02:00
|
|
|
|
2024-06-15 16:39:34 +02:00
|
|
|
#action-container {
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
2024-06-14 17:48:57 +02:00
|
|
|
</style>
|