-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpopup.js
54 lines (44 loc) · 1.94 KB
/
popup.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
document.addEventListener('DOMContentLoaded', function () {
browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
browser.tabs.sendMessage(tabs[0].id, { action: "getTimestamps" }, function (response) {
if (response && response.timestamps) {
currentMarkerIndex = response.currentMarkerIndex; // Get the current marker index
displayTimestamps(response.timestamps);
} else {
console.error('No response or timestamps received');
}
});
});
});
var currentMarkerIndex = -1; // Add this line to define currentMarkerIndex
function displayTimestamps(timestamps) {
var list = document.getElementById('timestampList');
list.innerHTML = ''; // Clear the list
timestamps.forEach(function (timestamp, index) {
var li = document.createElement('li');
li.textContent = `Timestamp: ${formatTimestamp(timestamp)}`;
// Highlight the current timestamp
if (index === currentMarkerIndex) {
li.style.color = 'red'; // Change the color as per your preference
}
list.appendChild(li);
});
}
function formatTimestamp(seconds) {
var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60;
return minutes.toString().padStart(2, '0') + ':' + remainingSeconds.toString().padStart(2, '0');
}
document.getElementById('resetButton').addEventListener('click', function () {
// Send a message to the active tab to reset timestamps
browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
browser.tabs.sendMessage(tabs[0].id, { action: "resetTimestamps" }, function (response) {
if (response && response.success) {
console.log('Timestamps reset successfully.');
displayTimestamps([]);
} else {
console.error('Failed to reset timestamps');
}
});
});
});