Skip to content

Commit 55d9cce

Browse files
authored
add this code so 2/1 thing works
1 parent 7a25bff commit 55d9cce

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

required.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,48 @@ document.addEventListener('DOMContentLoaded', () => {
4444
showCarousel(index);
4545
});
4646
});
47+
48+
async function checkYouTubeUploadToday() {
49+
const apiKey = "AIzaSyBe67a0-qIYhodHBj7FfSF2K6PrHOW0MEQ";
50+
const channelId = "UCM4Zvt9DVqzAHJOJoCgcF_g";
51+
const today = new Date().toISOString().split("T")[0];
52+
53+
const url = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${channelId}&part=snippet&order=date&maxResults=5`;
54+
55+
try {
56+
const response = await fetch(url);
57+
const data = await response.json();
58+
59+
for (const item of data.items) {
60+
const publishedDate = item.snippet.publishedAt.split("T")[0];
61+
if (publishedDate === today) {
62+
return {
63+
uploaded: true,
64+
title: item.snippet.title,
65+
time: item.snippet.publishedAt,
66+
};
67+
}
68+
}
69+
} catch (error) {
70+
console.error("YouTube API error:", error);
71+
}
72+
73+
return { uploaded: false };
74+
}
75+
76+
async function updateStatusWidget() {
77+
const result = await checkYouTubeUploadToday();
78+
const statusText = document.getElementById("statusText");
79+
80+
if (result.uploaded) {
81+
statusText.textContent = "✅ Productive Day";
82+
statusText.style.color = "lime";
83+
statusText.title = `Uploaded: ${result.title} at ${new Date(result.time).toLocaleTimeString()}`;
84+
} else {
85+
statusText.textContent = "😴 Free Day";
86+
statusText.style.color = "gray";
87+
statusText.title = "No upload detected today";
88+
}
89+
}
90+
91+
document.addEventListener("DOMContentLoaded", updateStatusWidget);

0 commit comments

Comments
 (0)