File size: 4,153 Bytes
46e03d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590cf21
46e03d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e42328a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!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>
        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 16px;
            padding: 16px;
        }
        .tile {
            border: 1px solid #ccc;
            border-radius: 8px;
            overflow: hidden;
            padding: 8px;
            text-align: center;
        }
        .thumbnail {
            width: 100%;
            height: auto;
        }
        .channel-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
        .title {
            font-size: 16px;
            font-weight: bold;
            margin: 8px 0;
        }
        .info {
            font-size: 14px;
            color: #666;
        }
    </style>
</head>
<body>
    <input type="text" id="query" placeholder="ζ€œη΄’γƒ―γƒΌγƒ‰γ‚’ε…₯εŠ›">
    <button onclick="fetchResults()">怜紒</button>
    <div id="results" class="grid"></div>

    <script>
        async function fetchResults() {
            const query = document.getElementById('query').value;
            if (!query) {
                alert("ζ€œη΄’γƒ―γƒΌγƒ‰γ‚’ε…₯εŠ›γ—γ¦γγ γ•γ„γ€‚");
                return;
            }
            const url = `https://api.codetabs.com/v1/proxy?quest=https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`;
            
            try {
                const response = await fetch(url);
                const text = await response.text();
                
                const match = text.match(/<script nonce="[^"]+">var ytInitialData = (.*?);<\/script>/);
                if (!match) {
                    document.getElementById('results').innerHTML = "γƒ‡γƒΌγ‚ΏγŒθ¦‹γ€γ‹γ‚ŠγΎγ›γ‚“γ§γ—γŸγ€‚";
                    return;
                }
                
                const jsonData = JSON.parse(match[1]);
                const results = jsonData.contents?.twoColumnSearchResultsRenderer?.primaryContents?.sectionListRenderer?.contents[0]?.itemSectionRenderer?.contents;
                
                if (!results) {
                    document.getElementById('results').innerHTML = "ζ€œη΄’η΅ζžœγŒθ¦‹γ€γ‹γ‚ŠγΎγ›γ‚“γ§γ—γŸγ€‚";
                    return;
                }
                
                const videoResults = results.filter(item => item.videoRenderer).map(item => item.videoRenderer);
                
                document.getElementById('results').innerHTML = videoResults.map(video => {
                    const videoId = video.videoId;
                    const title = video.title?.runs[0]?.text || "γ‚Ώγ‚€γƒˆγƒ«γͺし";
                    const thumbnail = video.thumbnail?.thumbnails.sort((a, b) => b.width - a.width)[0]?.url || "";
                    const lengthText = video.lengthText?.simpleText || "";
                    const viewCount = video.viewCountText?.simpleText || "";
                    const channelIcon = video.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail?.thumbnails[0]?.url || "";
                    return `
                        <div class="tile">
                            <a href="https://www.youtube.com/watch?v=${videoId}" target="_blank">
                                <img class="thumbnail" src="${thumbnail}" alt="${title}">
                            </a>
                            <div class="title">${title}</div>
                            <div class="info">${lengthText} ・ ${viewCount}</div>
                            <div>
                                ${channelIcon ? `<img class="channel-icon" src="${channelIcon}" alt="チャンネル">` : ""}
                            </div>
                        </div>
                    `;
                }).join('');
            } catch (error) {
                document.getElementById('results').innerHTML = "γ‚¨γƒ©γƒΌγŒη™Ίη”Ÿγ—γΎγ—γŸ: " + error.message;
            }
        }
    </script>
</body>
</html>