index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<div>Hello, World!</div>
<script>
window.onmouseup = function () {
const selectText = window.getSelection().toString();
if (selectText) {
alert(selectText);
}
};
</script>
</body>
</html>