// did this all by hand over like 3 hours
const videoChapters = [
  { start: 1.92, title: "i'm not tryna ruin your fun" },
  { start: 4.2, title: "but cook me burgers with cheese" },
  { start: 6.15, title: "oh please i'm begging you gene" },
  { start: 8.22, title: "cuz i can't rely on louise" },
  { start: 10.53, title: "no she's too mean" },
  { start: 12.22, title: "and i don't" },
  { start: 13.12, title: "care about pesto" },
  { start: 14.85, title: "no i'm not green" },
  { start: 16.71, title: "if you see me" },
  { start: 17.42, title: "out in quahog" },
  { start: 19.19, title: "say hi" },
  { start: 20.1, title: "but if you meet me at" },
  { start: 21.6, title: "the clam i'm a talkative guy" },
  { start: 24.3, title: "maybe we'll talk over beers" },
  { start: 26.2, title: "and remember the time" },
  { start: 28.17, title: "and we know even" },
  { start: 29.27, title: "at my lois" },
  { start: 30.37, title: "i'm a family guy" },
  { start: 32.25, title: "yeah a lot of white boys" },
  { start: 34.27, title: "do impressions of me" },
  { start: 36.43, title: "and you always see my" },
  { start: 37.66, title: "clips on your fyp" },
  { start: 40.1, title: "but that algorithm's" },
  { start: 41.65, title: "always tryna censor me" },
  { start: 43.95, title: "they're even worse than" },
  { start: 45.55, title: "the fellas at the FCC" },
  { start: 49.8, title: "next day i'm" },
  { start: 50.75, title: "walkin' to moe's" },
  { start: 52.1, title: "choked the boy" },
  { start: 53.15, title: "it's my fault" },
  { start: 54.15, title: "my life was comedy gold" },
  { start: 56, title: "but now it's just getting old" },
  { start: 58, title: "i look deep down" },
  { start: 59.1, title: "in my heart" },
  { start: 60, title: "know i should" },
  { start: 60.8, title: "be home with Marge" },
  { start: 62.1, title: "but work is just" },
  { start: 63.06, title: "getting hard" },
  { start: 64.15, title: "with mr. burns" },
  { start: 65.1, title: "still in charge" },
  { start: 66.1, title: "i wanna wake up and say" },
  { start: 68.1, title: "good morning USA" },
  { start: 70.05, title: "but i can't get out of bed" },
  { start: 71.95, title: "it's comfy here anyway" },
  { start: 73.95, title: "i think of" },
  { start: 74.65, title: "Hayley and Steve" },
  { start: 76, title: "what will i do" },
  { start: 76.75, title: "when they leave?" },
  { start: 77.8, title: "at least there's" },
  { start: 78.8, title: "Francine and Klaus" },
  { start: 79.87, title: "but Roger's still" },
  { start: 80.97, title: "in my house" },
  { start: 82, title: "out in quahog" },
  { start: 82.95, title: "say hi" },
  { start: 83.85, title: "but if you meet me at" },
  { start: 85.35, title: "the clam i'm a talkative guy" },
  { start: 88.2, title: "maybe we'll talk over beers" },
  { start: 90.4, title: "and remember the time" },
  { start: 92.15, title: "and we know even at my lois" },
  { start: 94.35, title: "i'm a family guy" },
  { start: 96.4, title: "yeah a lot of white boys" },
  { start: 98.42, title: "do impressions of me" },
  { start: 99.93, title: "and you always see my" },
  { start: 101.67, title: "clips on your fyp" },
  { start: 104.28, title: "but that algorithm's" },
  { start: 105.81, title: "always tryna censor me" },
  { start: 107.94, title: "they're even worse than" },
  { start: 109.62, title: "the fellas at the FCC" },
  { start: 113, title: ":)" },
];

const videoPlayer = document.getElementById("video");
const originalTitle = document.title;

function getCurrentChapterTitle(currentTime, chapters) {
  for (let i = chapters.length - 1; i >= 0; i--) {
    if (currentTime >= chapters[i].start) {
      return chapters[i].title;
    }
  }
  return originalTitle;
}

// i had to write the lyrics and timestamps manually because the video didn't have subtitles
videoPlayer.addEventListener("pause", () => {
  console.log(`Current timestamp: ${video.currentTime.toFixed(2)}`);
});

videoPlayer.addEventListener("timeupdate", () => {
  const currentTitle = getCurrentChapterTitle(
    videoPlayer.currentTime,
    videoChapters,
  );
  if (document.title !== currentTitle) {
    document.title = currentTitle;
  }
});

videoPlayer.addEventListener("ended", () => {
  document.title = ":)";
});
