summaryrefslogtreecommitdiff
path: root/www/scripts/elements/share.js
blob: d6813ba94578154836ad2268bbed1aa313fc243e (plain)
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
const shareBtn = document.getElementById("share-btn");

shareBtn.addEventListener("click", () => {
	share();
});

function share() {
	const data = {
		title: "altaf-creator",
		text: document.title,
		url: window.location,
	};

	iconChange();
	navigator.clipboard.writeText(window.location);
	navigator.share(data);
}

async function iconChange() {
	shareBtn.firstChild.setAttribute("class", "fa-solid fa-copy");
	await sleep(2000);
	shareBtn.firstChild.setAttribute("class", "fa-solid fa-share-nodes");
}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}