Skip to content

Commit

Permalink
Merge pull request #96 from Tomkndn/main
Browse files Browse the repository at this point in the history
Feat: Created a share button
  • Loading branch information
Ctoic authored Oct 15, 2024
2 parents c111eba + f01b0f0 commit 969d5fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ <h3 class="text-lg mt-2" id="author-gd1">By Richard Dawkins</h3>
><span class="tooltip" id="view">View comments</span></i
>
</div>
<button
id="share-link"
class="bg-green-500 text-white font-semibold py-2 px-4 rounded hover:bg-green-600 transition duration-200 mt-4"
>
Share
</button>
</div>
</div>
<div class="col-12 col-lg-8 ps-4">
Expand Down
34 changes: 34 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,40 @@ document.addEventListener("DOMContentLoaded", function () {
let allBooksList = [];
let currentBook;

const urlParams = new URLSearchParams(window.location.search);
const audioFile = urlParams.get("file");
const startTime = urlParams.get("t");

if (audioFile && startTime) {
audioPlayer.src = `audio/${audioFile}`;
audioPlayer.currentTime = startTime;
audioPlayer.play();
}

const shareBtn = document.getElementById("share-link");

shareBtn.addEventListener("click", () => {

const currentAudioFile = audioPlayer.src.split("/").pop();
const currentTime = audioPlayer.currentTime;

const currentUrl = `${
window.location.href
}?file=${currentAudioFile}&t=${Math.floor(currentTime)}`;
const shareText = `Check out this audio "${currentAudioFile}" starting at ${Math.floor(
currentTime
)} seconds!`;

navigator.clipboard
.writeText(currentUrl)
.then(() => {
alert(`Link copied to clipboard`);
})
.catch((err) => {
console.error("Failed to copy: ", err);
});
});

// Function to display error popup
function showErrorPopup(message) {
const overlay = document.createElement("div");
Expand Down

0 comments on commit 969d5fd

Please sign in to comment.