-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharebridge.html
66 lines (60 loc) · 2.38 KB
/
sharebridge.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portail de partage</title>
</head>
<body>
<h1>Partage!</h1>
<p>Vous êtes sur cette page car il vous a été demandé de partager un site ou um projet.</p>
<button id="shareButton">Partager!</button>
<div id="errorMessage" style="color: red;"></div>
<script>
const whitelist = ['https://xpeuvr327.github.io','http://lehostmaison.mywire.org', 'http://lesitedela104.webredirect.org','http://213.55.162.9', 'http://192.168.1.77'];
function getQueryParams() {
const params = new URLSearchParams(window.location.search);
return {
url: params.get('url'),
title: params.get('title'),
content: params.get('content')
};
}
function isReferrerAllowed() {
const referrer = document.referrer;
if (!referrer) return true;
if(referrer==undefined) return true;
const referrerOrigin = new URL(referrer).origin;
return whitelist.includes(referrerOrigin);
}
function initializeShareButton() {
const { url, title, content } = getQueryParams();
const shareButton = document.getElementById('shareButton');
const errorMessage = document.getElementById('errorMessage');
if (!isReferrerAllowed()) {
shareButton.disabled = true;
errorMessage.textContent=document.referrer;
return;
}
if (navigator.share) {
shareButton.addEventListener('click', async () => {
try {
await navigator.share({
title: title,
text: content,
url: url
});
console.log('Shared successfully');
} catch (error) {
console.error('Error sharing:', error);
}
});
} else {
shareButton.disabled = true;
shareButton.textContent = 'erreur: appareil peut-être trop ancien';
}
}
window.onload = initializeShareButton;
</script>
</body>
</html>