-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
76 lines (65 loc) · 2.74 KB
/
content.js
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
// Wait for the page to fully load
window.addEventListener('load', function() {
// Function to add the Subscribr link
function addSubscribrLink() {
// Check if the link already exists
if (document.getElementById('subscribr-link')) return;
// Get the container for the buttons
const buttonContainer = document.querySelector('#top-level-buttons-computed');
if (!buttonContainer) return;
// Create the Subscribr link
const subscribrLink = document.createElement('a');
subscribrLink.id = 'subscribr-link';
subscribrLink.style.marginRight = '8px'; // Adjust the margin as needed
subscribrLink.style.cursor = 'pointer';
// Create the image element for the icon
const icon = document.createElement('img');
icon.src = chrome.runtime.getURL('icon48.png');
icon.alt = 'Subscribr Video Breakdown';
icon.title = 'Subscribr Video Breakdown';
icon.style.width = '32px';
icon.style.height = '32px';
// Add the icon to the link
subscribrLink.appendChild(icon);
// Create the loading spinner
const spinner = document.createElement('div');
spinner.id = 'subscribr-spinner';
spinner.style.display = 'none';
spinner.style.width = '30px';
spinner.style.height = '30px';
spinner.style.border = '4px solid #EBB2A6'; // accent color
spinner.style.borderTop = '4px solid #CC3E21'; // primary color
spinner.style.borderRadius = '50%';
spinner.style.animation = 'spin 1s linear infinite';
subscribrLink.appendChild(spinner);
// Add click event to the link
subscribrLink.addEventListener('click', function() {
const videoId = new URLSearchParams(window.location.search).get('v');
if (videoId) {
// Show the spinner
icon.style.display = 'none';
spinner.style.display = 'block';
// Redirect after a short delay to simulate loading
setTimeout(() => {
window.location.href = `https://subscribr.ai/research/breakdown/${videoId}`;
}, 2000); // Adjust the delay as needed
}
});
// Insert the link into the container
buttonContainer.insertBefore(subscribrLink, buttonContainer.firstChild);
}
// Add the link when the page loads
addSubscribrLink();
// Add the link when the URL changes (e.g., navigating to a new video)
const observer = new MutationObserver(addSubscribrLink);
observer.observe(document.body, { childList: true, subtree: true });
});
// Add CSS for spinner animation
const style = document.createElement('style');
style.innerHTML = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`;
document.head.appendChild(style);