-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
61 lines (52 loc) · 2.16 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
55
56
57
58
59
60
61
// Добавление видео в историю
document.getElementById('addVideo').addEventListener('click', () => {
const videoUrl = document.getElementById('videoUrl').value.trim();
if (videoUrl) {
const videoItem = {
url: videoUrl,
timestamp: new Date().toLocaleString()
};
chrome.storage.local.get(['videoHistory'], (result) => {
const history = result.videoHistory || [];
history.push(videoItem);
chrome.storage.local.set({ videoHistory: history }, () => {
displayHistory();
document.getElementById('videoUrl').value = ''; // Очистить поле ввода
});
});
}
});
// Отображение истории
function displayHistory() {
chrome.storage.local.get(['videoHistory'], (result) => {
const historyList = document.getElementById('historyList');
historyList.innerHTML = ''; // Очищаем список
const history = result.videoHistory || [];
history.forEach(item => {
const historyItem = document.createElement('div');
historyItem.classList.add('history-item');
historyItem.textContent = `${item.url} — ${item.timestamp}`;
historyList.appendChild(historyItem);
});
});
}
// Очистка истории
document.getElementById('clearHistory').addEventListener('click', () => {
chrome.storage.local.remove(['videoHistory'], () => {
displayHistory(); // Обновить отображение истории
});
});
// Экспорт истории
document.getElementById('exportHistory').addEventListener('click', () => {
chrome.storage.local.get(['videoHistory'], (result) => {
const history = result.videoHistory || [];
const blob = new Blob([JSON.stringify(history)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'videoHistory.json';
link.click();
});
});
// Загрузка истории при открытии окна
displayHistory();