Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/assets/js/copyLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const copyBtn = document.getElementById("copyLink");

copyBtn.addEventListener("click", async () => {
try{

const timestamp = Math.floor(player.playerInfo.currentTime) || 0;
const url = window.location.href;
let link = url;
if (!url.includes("?")) {
link += `?t=${timestamp}`;
} else if (url.includes("t=")) {
link = url.replace(/t=\d+/, `t=${timestamp}`);
} else {
// this is for the case where there are other query strings
link += `&t=${timestamp}`;
}
await navigator.clipboard.writeText(link);
copyBtn.innerHTML = "Copied!";

// reset button text after 3 seconds
setTimeout(() => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a little animation here that gives some user feedback

copyBtn.innerHTML = "Copy link at current time";
}, 2000);
}catch(err){
console.error('Failed to copy: ', err);
}

});
3 changes: 2 additions & 1 deletion src/controllers/lessons.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const getLessonProgress = async (userId, lesson) => {

export const showLesson = async (req, res) => {
try {
const timeStart = req.query.t || 0;
let lesson = await Lesson.findOne({
permalink: req.params.permalink,
}).lean();
Expand All @@ -148,7 +149,7 @@ export const showLesson = async (req, res) => {
assigned = await getHwProgress(req.user.id, assigned);
if (due.length) due = await getHwProgress(req.user.id, due);
}
res.render("lesson", { lesson, next, prev, assigned, due });
res.render("lesson", { lesson, next, prev, assigned, due, timeStart });
} catch (err) {
console.log(err);
res.redirect("/class/all");
Expand Down
28 changes: 24 additions & 4 deletions src/views/lesson.pug
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ block content
if next
h3
a(href="/class/" + next) Next Class
button#copyLink.hidden.p-2.border.bg-pink-800.text-white.text-xs.font-medium.mt-4.rounded-md Copy link at current time


#info
if loggedIn
if lesson.videoId
Expand Down Expand Up @@ -84,13 +87,19 @@ block content
.mb-6(class="shadow-[0_2px_10px_0_rgba(0,0,0,0.1)]")
+homework(homework)



append scripts
script(src="/js/copyLink.js")
if loggedIn
script(src="/js/hwDone.js")
script(src="/js/hwProgress.js")
script(src="/js/lessonProgress.js")

script.
const timeStart = #{timeStart} || 0;
if lesson.videoId && !lesson.twitchVideo

script.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
Expand All @@ -100,12 +109,23 @@ append scripts
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: '#{lesson.videoId}' === 'o3IIobN4xR0' ? 'YRemMgGfbKg' : '#{lesson.videoId}',
playerVars: {
// this unfortunately doesn't work if the user is logged in and has 'youtube history' turned on
// see https://stackoverflow.com/questions/77691282/youtube-iframe-api-start-time-not-working-when-youtube-history-is-enabled for possible workaround (not implemented yet)
start: timeStart

},
events: {
'onReady': onPlayerReady,
}
});


}
function onPlayerReady(event) {
// this will lazy load the button
document.getElementById('copyLink').classList.remove('hidden');
}
//- function setCurrentTime(slideNum) {
//- var object = [ 0, 320 ];
//- player.seekTo(object[slideNum]);
//- }

else if lesson.twitchVideo
script(src="https://player.twitch.tv/js/embed/v1.js")
Expand Down