-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.js
More file actions
75 lines (63 loc) · 2.33 KB
/
Copy pathnotification.js
File metadata and controls
75 lines (63 loc) · 2.33 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
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
let audioContext = null;
let audioBuffer = null;
// Initialize audio context and load sound
async function initAudio() {
try {
// Create audio context
audioContext = new AudioContext();
// Load the sound file
const response = await fetch(chrome.runtime.getURL('bell.mp3'));
const arrayBuffer = await response.arrayBuffer();
audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
// Play the sound once initialized
playAlertSound();
} catch (error) {
console.error('Error initializing audio:', error);
}
}
// Function to play alert sound
function playAlertSound() {
if (!audioContext || !audioBuffer) {
console.log('Audio not initialized yet');
return;
}
try {
// Create source
const source = audioContext.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioContext.destination);
// Play the sound
source.start(0);
} catch (error) {
console.error('Error playing sound:', error);
}
}
document.addEventListener('DOMContentLoaded', () => {
// Get alert details from URL parameters
const urlParams = new URLSearchParams(window.location.search);
const alertId = urlParams.get('alertId');
const alertName = urlParams.get('alertName');
const targetWord = urlParams.get('targetWord');
const targetUrl = urlParams.get('targetUrl');
// Update the page with alert details
document.getElementById('alertName').textContent = alertName;
document.getElementById('targetWord').textContent = targetWord;
document.getElementById('targetUrl').textContent = targetUrl;
document.getElementById('timestamp').textContent = `Triggered at: ${new Date().toLocaleString()}`;
// Handle view button click
document.getElementById('viewBtn').addEventListener('click', () => {
chrome.tabs.create({ url: targetUrl });
});
// Handle close button click
document.getElementById('closeBtn').addEventListener('click', () => {
window.close();
});
// Initialize audio when user interacts with the page
document.addEventListener('click', () => {
if (!audioContext) {
initAudio();
}
}, { once: true });
// Try to initialize audio immediately
initAudio();
});