-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
83 lines (71 loc) · 2.54 KB
/
content.js
File metadata and controls
83 lines (71 loc) · 2.54 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
76
77
78
79
80
81
82
83
let peaks = [];
let notificationElement = null;
async function loadChatPeaks() {
try {
const response = await fetch(chrome.runtime.getURL('slopes_data.json'));
peaks = await response.json();
console.log(`Loaded ${peaks.length} chat peaks. Press 'Enter' to jump to the next peak.`);
} catch (error) {
console.error('Error loading slopes_data.json:', error);
}
}
function jumpToNextPeak() {
const video = document.querySelector('video');
if (!video || peaks.length === 0) return;
const currentTime = video.currentTime;
const nextPeak = peaks.find(peak => peak.top.time > currentTime);
if (nextPeak) {
video.currentTime = Math.max(0, nextPeak.before.time);
console.log(`Jumped to quiet period at ${formatTime(nextPeak.before.time)} before peak at ${formatTime(nextPeak.top.time)}`);
} else {
console.log("No more peaks ahead!");
}
}
function formatTime(seconds) {
return new Date(seconds * 1000).toISOString().substr(11, 8);
}
function toggleNotification(message) {
if (message) {
if (!notificationElement) {
notificationElement = document.createElement('div');
notificationElement.style.cssText = `
position: fixed; top: 20px; left: 20px; background-color: rgba(0, 0, 0, 0.8);
color: white; padding: 10px; border-radius: 5px; z-index: 9999;
`;
document.body.appendChild(notificationElement);
}
notificationElement.textContent = message;
} else if (notificationElement) {
notificationElement.remove();
notificationElement = null;
}
}
function checkForPeakWindow() {
const video = document.querySelector('video');
if (!video || peaks.length === 0) return;
const currentTime = video.currentTime;
const currentPeak = peaks.find(peak =>
currentTime >= peak.before.time && currentTime <= peak.top.time
);
if (currentPeak) {
const messageCount = currentPeak.top.count - currentPeak.before.count;
toggleNotification(
`Approaching peak: ${formatTime(currentPeak.before.time)} → ${formatTime(currentPeak.top.time)}\n` +
`Message increase: ${currentPeak.before.count} → ${currentPeak.top.count} (+${messageCount})`
);
} else {
toggleNotification(null);
}
}
document.addEventListener('keydown', event => {
if (event.key === 'Enter') {
jumpToNextPeak();
}
});
loadChatPeaks();
setInterval(checkForPeakWindow, 1000);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "get_peaks_status") {
sendResponse({status: "Chat peaks loaded. Press 'Enter' to jump to peaks."});
}
});