選択したテキストを取得する window.getSelection()

<p id="text">色は匂へど 散りぬるを 我が世誰ぞ 常ならむ 有為の奥山 今日越えて 浅き夢見じ 酔ひもせず</p>
const text = document.getElementById("text");
const balloon = document.getElementById("balloon");
text.addEventListener("selectstart", () => {
  text.addEventListener("mouseup", () => {
    console.log(window.getSelection().toString());
  });
});

window.getSelection() は選択範囲を返すメソッド。
toString()を末尾に付与することで選択中の文字列を返す。