mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/Omnibox: download right after pasting
This commit is contained in:
parent
d008bffc08
commit
b2652f29ac
2 changed files with 12 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SvelteComponent, tick } from "svelte";
|
||||||
|
|
||||||
import IconLink from "@tabler/icons-svelte/IconLink.svelte";
|
import IconLink from "@tabler/icons-svelte/IconLink.svelte";
|
||||||
|
|
||||||
import ClearButton from "$components/save/buttons/ClearButton.svelte";
|
import ClearButton from "$components/save/buttons/ClearButton.svelte";
|
||||||
|
@ -17,6 +19,8 @@
|
||||||
let link: string = "";
|
let link: string = "";
|
||||||
let isFocused = false;
|
let isFocused = false;
|
||||||
|
|
||||||
|
let downloadButton: SvelteComponent;
|
||||||
|
|
||||||
const validLink = (link: string) => {
|
const validLink = (link: string) => {
|
||||||
try {
|
try {
|
||||||
return /^https:/i.test(new URL(link).protocol);
|
return /^https:/i.test(new URL(link).protocol);
|
||||||
|
@ -26,10 +30,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const pasteClipboard = () => {
|
const pasteClipboard = () => {
|
||||||
navigator.clipboard.readText().then((text) => {
|
navigator.clipboard.readText().then(async (text) => {
|
||||||
let matchLink = text.match(/https:\/\/[^\s]+/g);
|
let matchLink = text.match(/https:\/\/[^\s]+/g);
|
||||||
if (matchLink) {
|
if (matchLink) {
|
||||||
link = matchLink[0];
|
link = matchLink[0];
|
||||||
|
|
||||||
|
await tick(); // wait for button to render
|
||||||
|
downloadButton.download(link);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -62,7 +69,7 @@
|
||||||
<ClearButton click={() => (link = "")} />
|
<ClearButton click={() => (link = "")} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if validLink(link)}
|
{#if validLink(link)}
|
||||||
<DownloadButton url={link} />
|
<DownloadButton url={link} bind:this={downloadButton} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
|
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
|
||||||
|
|
||||||
export const changeDownloadButton = (state: string) => {
|
const changeDownloadButton = (state: string) => {
|
||||||
isDisabled = true;
|
isDisabled = true;
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case "think":
|
case "think":
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const restoreDownloadButton = () => {
|
const restoreDownloadButton = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
buttonText = '>>';
|
buttonText = '>>';
|
||||||
isDisabled = false;
|
isDisabled = false;
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// alerts are temporary, we don't have an error popup yet >_<
|
// alerts are temporary, we don't have an error popup yet >_<
|
||||||
const download = async (link: string) => {
|
export const download = async (link: string) => {
|
||||||
changeDownloadButton("think");
|
changeDownloadButton("think");
|
||||||
|
|
||||||
const response = await API.request(link);
|
const response = await API.request(link);
|
||||||
|
|
Loading…
Reference in a new issue