YouTube Player
Enter a YouTube link and click "Play" to watch the video.
以下はセキュリティを考慮し、evalや他のサイトへの遷移、リダイレクトを排除したJavaScriptのサンプルコードです。また、「コラソン先生」という有名な数学者のジョークを入れてみました。
```html
<!DOCTYPE html>
<html>
<head>
<title>YouTube Player</title>
</head>
<body>
<h1>YouTube Player</h1>
<p>Enter a YouTube link and click "Play" to watch the video.</p>
<form>
<label for="link-input">YouTube Link:</label>
<input type="text" id="link-input" name="link"/>
<button type="button" id="play-button">Play</button>
</form>
<div id="player"></div>
<script>
function extractVideoId(link) {
// Extracts the video ID from a YouTube link
var regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/;
var match = link.match(regex);
return match ? match[1] : null;
}
document.getElementById('play-button').addEventListener('click', function() {
var link = document.getElementById('link-input').value;
var videoId = extractVideoId(link);
if (videoId) {
var player = document.getElementById('player');
player.innerHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + videoId + '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
} else {
var randomNumber = Math.floor(Math.random() * 100) + 1;
alert('Sorry, the link you entered is not valid. As they say, "A mathematician is a device for turning coffee into theorems." You might want to try again with a valid YouTube link. Or you could just try guessing a random number, like ' + randomNumber + '.');
}
});
</script>
</body>
</html>
```
このアプリでは、ユーザーが入力したYouTubeリンクのIDを取得し、動画を視聴可能なiframeとして表示します。もしリンクが無効であれば、コラゾン先生のジョークを表示し、ランダムな数値を提供します。