Support copy pasting links in web app

This commit is contained in:
Brahim Hadriche committed 2023-10-27 16:32:11 -04:00
1 parent af020b509a
commit bde4523c00
2 files changed
+23 -6

No files matched your search

+1
View File
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Pagination support in web app search (load more button)
- Video links pasted into the web app triggers the dialog to cast the video
## [0.14.0] - 2023-10-25
+22 -6
View File
@@ -30,13 +30,22 @@
onMount(async () => {
document.body.addEventListener("drop", onDrop);
document.body.addEventListener("dragover", onDragOver);
document.body.addEventListener("paste", onPaste);
});
onDestroy(() => {
document.body.removeEventListener("drop", onDrop);
document.body.removeEventListener("dragover", onDragOver);
document.body.removeEventListener("paste", onPaste);
});
async function onPaste(event) {
modal.close();
const dataString = event.clipboardData.getData("text/plain");
await processUrlText(dataString);
}
async function onDrop(event) {
event.preventDefault();
modal.close();
@@ -48,6 +57,12 @@
let dataString = (await new Promise((resolve) =>
item.getAsString(resolve)
)) as string;
await processUrlText(dataString);
}
}
}
async function processUrlText(dataString: string) {
if (isValidHttpUrl(dataString)) {
const videoInfo = parseYouTubeUrl(dataString);
if (videoInfo.videoId) {
@@ -64,8 +79,6 @@
}
}
}
}
}
async function searchForVideoById(videoId, timestamp) {
try {
@@ -101,14 +114,17 @@
event.preventDefault();
}
function isValidHttpUrl(string) {
let url;
function isValidHttpUrl(url) {
if (!url) {
return false;
}
let urlObj;
try {
url = new URL(string);
urlObj = new URL(url);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
return urlObj.protocol === "http:" || urlObj.protocol === "https:";
}
function parseYouTubeUrl(url) {