mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-10 15:28:29 +00:00
feature-web: allow pasting of valid URLs from clipboard
This commit is contained in:
parent
4d2c8b0a8c
commit
f29b4f7cb5
@ -2,6 +2,8 @@ const allowedLinkTypes = new Set(["text/plain", "text/uri-list"]);
|
|||||||
|
|
||||||
export const pasteLinkFromClipboard = async () => {
|
export const pasteLinkFromClipboard = async () => {
|
||||||
const clipboard = await navigator.clipboard.read();
|
const clipboard = await navigator.clipboard.read();
|
||||||
|
let pastedText = null;
|
||||||
|
|
||||||
|
|
||||||
if (clipboard?.length) {
|
if (clipboard?.length) {
|
||||||
const clipboardItem = clipboard[0];
|
const clipboardItem = clipboard[0];
|
||||||
@ -9,9 +11,20 @@ export const pasteLinkFromClipboard = async () => {
|
|||||||
if (allowedLinkTypes.has(type)) {
|
if (allowedLinkTypes.has(type)) {
|
||||||
const blob = await clipboardItem.getType(type);
|
const blob = await clipboardItem.getType(type);
|
||||||
const blobText = await blob.text();
|
const blobText = await blob.text();
|
||||||
|
try {
|
||||||
|
new URL(blobText);
|
||||||
|
pastedText = blobText;
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Content '${blobText}' is not a valid URL.`);
|
||||||
|
}
|
||||||
|
|
||||||
return blobText;
|
}
|
||||||
}
|
}
|
||||||
|
if(pastedText){
|
||||||
|
return pastedText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,13 +9,9 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"module": "esnext",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"types": ["turnstile-types"],
|
"types": ["turnstile-types"],
|
||||||
"lib": ["WebWorker"]
|
"lib": ["WebWorker"]
|
||||||
}
|
}
|
||||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
|
||||||
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
|
|
||||||
//
|
|
||||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
|
||||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user