1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

YouTubeタイマーでモーニングコールサービス

1
Last updated at Posted at 2026-02-14

前回のYouTubeタイマーにプリセット機能をつけました。

前回アップしたYoutube TimerにJsonでプリセット動画を複数追加して使いやすくしてみました。
時刻指定で動画を再生するので生成AIでモーニングコール動画を5本作ってサンプルにしています。

前回のYoutubeタイマーはこちら
Youtubeタイマー

モーニングコールの公開サイトはこちら
モーニングコールサービスサイト

残念ながらiPhoneでは動きませんでした。
Androidでは動くのですが、ブラウザが起動してスリープしていない状態になっていないと動きません。
なのでPC用と思ってください。

使い方は、Youtubeタイマーとほぼ変わらないので省略します。

ソース

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube タイマー (リスト選択版)</title>
    <style>
        body { font-family: 'Helvetica Neue', Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background-color: #f8f9fa; margin: 0; color: #333; }
        .container { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); text-align: center; width: 90%; max-width: 500px; }
        h2 { margin-top: 0; color: #ff0000; }
        .form-group { margin-bottom: 15px; text-align: left; }
        label { display: block; font-size: 0.9rem; margin-bottom: 5px; color: #666; }
        select, input, button { width: 100%; padding: 12px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 6px; box-sizing: border-box; font-size: 1rem; }
        button { background-color: #ff0000; color: white; border: none; font-weight: bold; cursor: pointer; transition: background 0.3s; }
        button:hover { background-color: #cc0000; }
        #player { margin-top: 20px; border-radius: 8px; overflow: hidden; }
        .status { font-weight: bold; padding: 10px; border-radius: 4px; background: #fff3f3; color: #d32f2f; }
    </style>
</head>
<body>

<div class="container">
    <h2>Youtubeモーニングコール</h2>
    
    <div class="form-group">
        <label>プリセットから選ぶ</label>
        <select id="videoSelect" onchange="updateVideoId()">
            <option value="">-- 選択してください --</option>
        </select>
    </div>

    <div class="form-group">
        <label>動画ID(手入力もOK)</label>
        <input type="text" id="videoId" placeholder="例:dQw4w9WgXcQ">
    </div>

    <div class="form-group">
        <label>再生予約時刻</label>
        <input type="time" id="targetTime" step="1">
    </div>
    
    <button onclick="setTimer()">タイマーをセット</button>
    <p id="message">時刻を設定してセットしてください</p>

    <div id="player"></div>
</div>

<script>
    // --- JSONデータ: ここを書き換えるだけでリストを増やせます ---
    const videoListData = [
        { "name": "通常モーニングコール", "id": "JEgteg1Bwzo" },
        { "name": "怖い姉バージョン", "id": "VdjDTWSAKqo" },
        { "name": "優しい姉バージョン", "id": "8t5YVycvQuw" },
        { "name": "姉を起こすバージョン", "id": "_7ni-mlJ2yk" },
        { "name": "兄を起こすバージョン", "id": "SK6hG494TwY" }
    ];
    let player;
    let timerId = null;

    // 初期化:セレクトボックスにJSONデータを流し込む
    window.onload = () => {
        const select = document.getElementById('videoSelect');
        videoListData.forEach(item => {
            const option = document.createElement('option');
            option.value = item.id;
            option.textContent = item.name;
            select.appendChild(option);
        });
    };

    // リスト選択時にテキストボックスを更新
    function updateVideoId() {
        const select = document.getElementById('videoSelect');
        if (select.value) {
            document.getElementById('videoId').value = select.value;
        }
    }

    // YouTube API 読み込み
    const tag = document.createElement('script');
    tag.src = "https://www.youtube.com/iframe_api";
    document.head.appendChild(tag);

    function setTimer() {
        const vId = document.getElementById('videoId').value;
        const targetTime = document.getElementById('targetTime').value;

        if (!vId || !targetTime) {
            alert("動画IDと時刻の両方を設定してください");
            return;
        }

        if (timerId) clearInterval(timerId);
        document.getElementById('message').className = "status";
        document.getElementById('message').innerText = `予約完了: ${targetTime} に再生します`;

        timerId = setInterval(() => {
            const now = new Date();
            const currentTime = 
                String(now.getHours()).padStart(2, '0') + ":" + 
                String(now.getMinutes()).padStart(2, '0') + ":" + 
                String(now.getSeconds()).padStart(2, '0');

            if (currentTime === targetTime) {
                clearInterval(timerId);
                playVideo(vId);
            }
        }, 1000);
    }

    function playVideo(vId) {
        document.getElementById('message').innerText = "再生中!";
        if (player) player.destroy();

        player = new YT.Player('player', {
            height: '280',
            width: '100%',
            videoId: vId,
            playerVars: { 'autoplay': 1, 'mute': 0, 'playsinline': 1 },
            events: { 'onReady': (e) => e.target.playVideo() }
        });
    }
</script>

</body>

改修箇所
devタグのclass="container"の直下にあるH2タグの内容が赤字で表示されたタイトルです。
Scriptタグの const videoListData の内容を書き換えることでプリセット内容を変えることができます。

このindex.htmlをレンタルサーバー等に貼り付ければモーニングコールサービスの出来上がりです。

商用利用したい方へ

このソースを商用利用サイトを作りたい方は、m_kawase@embed-ai.comまでご相談くださいませ。
動画IDを自動取得したり、データベース化することで個人カスタマイズ可能なものを作れます。

個人利用の方はコメント欄にサイトURLを教えてください!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?