Support copy pasting links in web app
This commit is contained in:
1 parent
af020b509a
commit
bde4523c00
2 files changed
+23
-6
No files matched your search
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Pagination support in web app search (load more button)
|
- 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
|
## [0.14.0] - 2023-10-25
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,22 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
document.body.addEventListener("drop", onDrop);
|
document.body.addEventListener("drop", onDrop);
|
||||||
document.body.addEventListener("dragover", onDragOver);
|
document.body.addEventListener("dragover", onDragOver);
|
||||||
|
document.body.addEventListener("paste", onPaste);
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
document.body.removeEventListener("drop", onDrop);
|
document.body.removeEventListener("drop", onDrop);
|
||||||
document.body.removeEventListener("dragover", onDragOver);
|
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) {
|
async function onDrop(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
modal.close();
|
modal.close();
|
||||||
@@ -48,6 +57,12 @@
|
|||||||
let dataString = (await new Promise((resolve) =>
|
let dataString = (await new Promise((resolve) =>
|
||||||
item.getAsString(resolve)
|
item.getAsString(resolve)
|
||||||
)) as string;
|
)) as string;
|
||||||
|
await processUrlText(dataString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processUrlText(dataString: string) {
|
||||||
if (isValidHttpUrl(dataString)) {
|
if (isValidHttpUrl(dataString)) {
|
||||||
const videoInfo = parseYouTubeUrl(dataString);
|
const videoInfo = parseYouTubeUrl(dataString);
|
||||||
if (videoInfo.videoId) {
|
if (videoInfo.videoId) {
|
||||||
@@ -64,8 +79,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function searchForVideoById(videoId, timestamp) {
|
async function searchForVideoById(videoId, timestamp) {
|
||||||
try {
|
try {
|
||||||
@@ -101,14 +114,17 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidHttpUrl(string) {
|
function isValidHttpUrl(url) {
|
||||||
let url;
|
if (!url) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let urlObj;
|
||||||
try {
|
try {
|
||||||
url = new URL(string);
|
urlObj = new URL(url);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return url.protocol === "http:" || url.protocol === "https:";
|
return urlObj.protocol === "http:" || urlObj.protocol === "https:";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseYouTubeUrl(url) {
|
function parseYouTubeUrl(url) {
|
||||||
|
|||||||
Reference in new issue
Block a user