`;
containerEl.appendChild(item);
});
}
}
window.removeFromPlaylist = function(index) {
playlist.splice(index, 1);
savePlaylist();
renderPlaylist();
};
window.moveInPlaylist = function(index, direction) {
if (direction === -1 && index > 0) {
, playlist[index - 1]] = , playlist[index]];
} else if (direction === 1 && index < playlist.length - 1) {
[playlist[index], playlist[index + 1]] = [playlist[index + 1], playlist[index]];
}
savePlaylist();
renderPlaylist();
};
window.changeTab = function(tabIndex) {
const tabs = document.querySelectorAll('.tab');
const tabContents = document.querySelectorAll('.tab-content');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
tabs[currentTabIndex].classList.remove('active');
tabContents[currentTabIndex].classList.remove('active');
currentTabIndex = tabIndex;
tabs[currentTabIndex].classList.add('active');
tabContents[currentTabIndex].classList.add('active');
prevBtn.disabled = currentTabIndex === 0;
nextBtn.disabled = currentTabIndex === tabs.length - 1;
if (tabIndex === 1) {
renderPlaylist();
}
};
window.navigateTabs = (direction) => changeTab(currentTabIndex + direction);
window.downloadPDF = function() {
if (playlist.length === 0) {
alert("Your playlist is empty. Add some videos before downloading.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(20);
doc.text("My Educational Video Playlist", 14, 22);
const tableBody = playlist.map((video, index) => [
index + 1,
video.title,
video.channel,
`https://www.youtube.com/watch?v=${video.id}`
]);
doc.autoTable({
head: [['#', 'Title', 'Channel', 'Link']],
body: tableBody,
startY: 30,
theme: 'grid',
headStyles: { fillColor: [79, 70, 229] }, // Indigo
didDrawCell: (data) => {
if (data.column.index === 3 && data.cell.section === 'body') {
doc.setTextColor(0, 0, 255);
doc.setFont(undefined, 'underline');
}
}
});
doc.save('educational_video_playlist.pdf');
};
// Initial Load
loadPlaylist();
searchVideos(); // Show initial set of videos
});