-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.js
72 lines (61 loc) · 2.65 KB
/
history.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
document.addEventListener("DOMContentLoaded", () => {
loadHistory();
document.getElementById("clear-button").addEventListener("click", () => {
if (confirm("Вы уверены, что хотите очистить историю запросов?")) {
chrome.storage.local.set({ history: [] }, () => { // Очищаем только историю
loadHistory();
alert("История запросов очищена.");
});
}
});
});
function loadHistory() {
chrome.storage.local.get(['history'], (data) => { // Получаем только историю
const history = data.history || [];
chrome.storage.sync.get(['historyLimit'], (settings) => { // Получаем historyLimit из storage.sync
const historyLimit = typeof settings.historyLimit === 'number' ? settings.historyLimit : 20; // По умолчанию 20
const tableBody = document.getElementById("history-table-body");
tableBody.innerHTML = ""; // Очистка таблицы
if (historyLimit === 0) {
const row = document.createElement("tr");
const cell = document.createElement("td");
cell.colSpan = 4;
cell.textContent = "История отключена.";
cell.style.textAlign = "center";
row.appendChild(cell);
tableBody.appendChild(row);
return;
}
if (history.length === 0) {
const row = document.createElement("tr");
const cell = document.createElement("td");
cell.colSpan = 4;
cell.textContent = "История пуста.";
cell.style.textAlign = "center";
row.appendChild(cell);
tableBody.appendChild(row);
return;
}
history.forEach(entry => {
const row = document.createElement("tr");
const dateCell = document.createElement("td");
dateCell.textContent = entry.date;
row.appendChild(dateCell);
const timeCell = document.createElement("td");
timeCell.textContent = entry.time;
row.appendChild(timeCell);
const queryCell = document.createElement("td");
const queryPre = document.createElement("pre");
queryPre.textContent = entry.query;
queryCell.appendChild(queryPre);
row.appendChild(queryCell);
const responseCell = document.createElement("td");
const responsePre = document.createElement("pre");
responsePre.textContent = entry.response;
responseCell.appendChild(responsePre);
row.appendChild(responseCell);
tableBody.appendChild(row);
});
});
});
}