initial comit
1 parent 96099e9 commit 08735dc15014b53e918745a56d0317e09bffacd3
root authored on 25 May 2022
Showing 13 changed files
View
Examples/demo_01.png 0 → 100755
View
Examples/demo_02.png 0 → 100755
View
Examples/demo_03.png 0 → 100755
View
30
README.md
WebShareDemo
===============
 
A small demo showing how to use the "web share target API" to upload an image
A small demo showing how to use the "web share target API" to upload an image.
 
1) Create a folder "ws3" in your webroot and add these files in it.
 
2) Replace demo.com with your URL in all the nessessecary files.
 
3) On your device go to https://[yourURL.com]/ws3/install.html and click "install"
 
4) now in your share menu's you should have this as an option (see below)
 
![demo 01](Examples/demo_01.png)
 
![demo 02](Examples/demo_02.png)
 
![demo 03](Examples/demo_03.png)
View
face_share-192.png 0 → 100755
View
face_share-512.png 0 → 100755
View
24
index.html 0 → 100644
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Share Target Demo</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="./style.css">
<!-- Manifest -->
<link rel="manifest" href="./manifest.json">
</head>
<body>
<h1>
Img Upload Demo
</h1>
<p>
<b>Latest pic:</b>
</p>
<p>
<img src="//demo.com/ws3/pic.jpg" width="100%" />
</body>
</html>
View
54
install.html 0 → 100644
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Share Target Demo</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="./style.css">
<!-- Manifest -->
<link rel="manifest" href="./manifest.json">
</head>
<body>
<h1>
Web Share Target Demo
</h1>
<p id="requireHTTPS" class="hidden">
<b>STOP!</b> This page <b>must</b> be served over HTTPS.
Please <a>reload this page via HTTPS</a>.
</p>
<p>
The Web Share Target API allows installed web apps to register
with the underlying OS as a share target to receive shared content
from either the Web Share API or system events, like the
OS-level share button.
</p>
<p id="shareNotSupported" class="hidden">
<code>navigator.share</code> is not supported in this
browser, try sharing from another app instead.
</p>
<p id="instructions">
<b>Try it out:</b>
Install me, then try sharing an image from another app.
</p>
<pre id="result">
</pre>
 
<!-- Install/Share buttons, disabled by default -->
<div id="installContainer">
<button id="butInstall" type="button" disabled>
Install
</button>
</div>
 
<!-- import the webpage's javascript file -->
<script src="./script.js"></script>
</body>
</html>
View
39
manifest.json 0 → 100644
{
"short_name": "Share Image",
"name": "Upload Image",
"share_target": {
"action": "share.php",
"method":"POST",
"enctype": "multipart/form-data",
"params": {
"title": "title",
"text": "text",
"url": "url",
"files": [
{
"name": "image",
"accept": "image/*"
}
]
 
}
},
"description": "Upload Image",
"icons": [
{
"src": "https://demo.com/ws3/face_share-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "https://demo.com/ws3/face_share-512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "index.html",
"background_color": "#c6f2f7",
"display": "standalone",
"scope": "/ws3/",
"theme_color": "#14168c"
}
View
54
script.js 0 → 100644
const divResult = document.getElementById('result');
const divInstall = document.getElementById('installContainer');
const butInstall = document.getElementById('butInstall');
 
window.addEventListener('beforeinstallprompt', (event) => {
console.log('👍', 'beforeinstallprompt', event);
// Stash the event so it can be triggered later.
window.deferredPrompt = event;
// Remove the 'hidden' class from the install button container
butInstall.removeAttribute('disabled');
});
 
butInstall.addEventListener('click', () => {
console.log('👍', 'butInstall-clicked');
const promptEvent = window.deferredPrompt
if (!promptEvent) {
// The deferred prompt isn't available.
return;
}
// Show the install prompt.
promptEvent.prompt();
// Log the result
promptEvent.userChoice.then((result) => {
console.log('👍', 'userChoice', result);
// Reset the deferred prompt variable, since
// prompt() can only be called once.
window.deferredPrompt = null;
// Hide the install button.
butInstall.setAttribute('disabled', true);
});
});
 
window.addEventListener('appinstalled', (event) => {
console.log('👍', 'appinstalled', event);
});
 
/* Only register a service worker if it's supported */
if ('serviceWorker' in navigator) {
console.log('👍', 'navigator.serviceWorker is supported');
navigator.serviceWorker.register('https://demo.com/ws3/service-worker.js');
}
 
/**
* Warn the page must be served over HTTPS
* The `beforeinstallprompt` event won't fire if the page is served over HTTP.
* Installability requires a service worker with a fetch event handler, and
* if the page isn't served over HTTPS, the service worker won't load.
*/
if (window.location.protocol === 'http:') {
const requireHTTPS = document.getElementById('requireHTTPS');
const link = requireHTTPS.querySelector('a');
link.href = window.location.href.replace('http://', 'https://');
requireHTTPS.classList.remove('hidden');
}
View
service-worker.js 0 → 100644
View
share.php 0 → 100644
View
style.css 0 → 100644
Buy Me A Coffee