-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
49 lines (42 loc) · 1.59 KB
/
content.js
File metadata and controls
49 lines (42 loc) · 1.59 KB
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
// Create and inject the reminder message
function createReminderMessage() {
// Only inject on YouTube main site, not YouTube Music
if (window.location.hostname !== 'www.youtube.com' || window.location.pathname.startsWith('/music')) return;
// Only show reminder if we have temporary access
chrome.storage.local.get(['tempYoutubeAccess'], (result) => {
if (!result.tempYoutubeAccess) return;
// Create and show the reminder message
const reminderDiv = document.createElement('div');
reminderDiv.className = 'yt-reminder-message';
reminderDiv.textContent = 'Remember, you are in control of your time. If you\'re here with intention, enjoy!';
// Add to the page
document.body.appendChild(reminderDiv);
// Show the message with a slight delay
setTimeout(() => {
reminderDiv.classList.add('show');
}, 500);
// Hide the message after 5 seconds
setTimeout(() => {
reminderDiv.classList.add('fade-out');
// Remove from DOM after animation
setTimeout(() => reminderDiv.remove(), 300);
}, 5000);
});
}
// Initialize on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createReminderMessage);
} else {
createReminderMessage();
}
// Also handle YouTube's dynamic navigation
let lastUrl = location.href;
new MutationObserver(() => {
const url = location.href;
if (url !== lastUrl) {
lastUrl = url;
if (location.hostname === 'www.youtube.com' && !location.pathname.startsWith('/music')) {
createReminderMessage();
}
}
}).observe(document, { subtree: true, childList: true });