From dc1a459b9779a707a0dc2b1b56ff2a4a84b394e6 Mon Sep 17 00:00:00 2001 From: Brunwo Date: Tue, 8 Oct 2024 01:00:27 +0200 Subject: [PATCH] trying fix share-target not included in build --- public/manifest.json | 2 +- public/share-target.html | 12 ++++++++++++ public/share-target.js | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 public/share-target.html create mode 100644 public/share-target.js diff --git a/public/manifest.json b/public/manifest.json index 1ccff57..2d4faab 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -25,7 +25,7 @@ } ], "share_target": { - "action": "share-target/", + "action": "share-target", "method": "GET", "params": { "title": "title", diff --git a/public/share-target.html b/public/share-target.html new file mode 100644 index 0000000..c35e8c5 --- /dev/null +++ b/public/share-target.html @@ -0,0 +1,12 @@ + + + + + + Handling Share... + + +

Handling shared content...

+ + + \ No newline at end of file diff --git a/public/share-target.js b/public/share-target.js new file mode 100644 index 0000000..4467082 --- /dev/null +++ b/public/share-target.js @@ -0,0 +1,16 @@ +// This function will be called when the PWA receives a share +function handleShareTarget() { + const urlParams = new URLSearchParams(window.location.search); + const sharedUrl = urlParams.get('url') || urlParams.get('text'); + + if (sharedUrl) { + // Redirect to the main page with the shared URL as a parameter + window.location.href = `index.html?url=${encodeURIComponent(sharedUrl)}`; + } else { + // If no URL is shared, just go to the main page + window.location.href = 'index.html'; + } +} + +// Call the function when the page loads +handleShareTarget(); \ No newline at end of file