-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
219 lines (186 loc) · 7.93 KB
/
script.js
File metadata and controls
219 lines (186 loc) · 7.93 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
let acceptCount = parseInt(localStorage.getItem('acceptCount')) || 0;
let declineCount = parseInt(localStorage.getItem('declineCount')) || 0;
const cellColors = JSON.parse(localStorage.getItem('cellColors')) || Array(100).fill('#00FF00');
let acceptedCount = cellColors.filter(color => color === '#00FF00').length;
let declinedCount = cellColors.filter(color => color === '#FF0000').length;
let isLocked = localStorage.getItem('isLocked') === 'true';
// Переменная для отслеживания номера
let currentNumber = parseInt(localStorage.getItem('currentNumber')) || 1;
let cellTexts = JSON.parse(localStorage.getItem('cellTexts')) || Array(100).fill('');
function updateAcceptanceRate() {
const acceptanceRate = (acceptedCount / 100) * 100;
document.getElementById('acceptance-rate').textContent = `Acceptance Rate: ${acceptanceRate.toFixed(2)}%`;
}
function updateDisplayCounts() {
document.getElementById('accept-count').textContent = acceptCount;
document.getElementById('decline-count').textContent = declineCount;
localStorage.setItem('acceptCount', acceptCount);
localStorage.setItem('declineCount', declineCount);
}
function paint(color) {
const colorCode = color === 'red' ? '#FF0000' : '#00FF00';
if (cellColors[99] === '#00FF00') {
acceptedCount--;
//acceptCount--;
} else if (cellColors[99] === '#FF0000') {
declinedCount--;
declineCount--;
}
for (let i = cellColors.length - 1; i > 0; i--) {
cellColors[i] = cellColors[i - 1];
document.getElementById(`cell-${i}`).style.backgroundColor = cellColors[i];
document.getElementById(`cell-${i}`).textContent = document.getElementById(`cell-${i-1}`).textContent;
}
cellColors[0] = colorCode;
document.getElementById('cell-0').style.backgroundColor = colorCode;
// Пропуск нумерации красной ячейки
if (colorCode === '#00FF00') {
document.getElementById('cell-0').textContent = currentNumber;
acceptCount++;
acceptedCount++;
currentNumber++;
} else {
document.getElementById('cell-0').textContent = ''; // Оставить пустым для красной
declineCount++;
declinedCount++;
}
if (currentNumber > 100) {
currentNumber = 1;
}
localStorage.setItem('currentNumber', currentNumber);
updateDisplayCounts();
localStorage.setItem('cellColors', JSON.stringify(cellColors));
// Сохранение текстов ячеек
const cellTexts = Array.from(document.querySelectorAll('.cell')).map(cell => cell.textContent);
localStorage.setItem('cellTexts', JSON.stringify(cellTexts));
updateAcceptanceRate();
}
function toggleCellColor(cellIndex) {
if (!isLocked) {
const currentColor = cellColors[cellIndex];
const newColor = currentColor === '#00FF00' ? '#FF0000' : '#00FF00';
if (currentColor !== newColor) {
cellColors[cellIndex] = newColor;
document.getElementById(`cell-${cellIndex}`).style.backgroundColor = newColor;
if (newColor === '#00FF00') {
acceptedCount++;
declinedCount--;
// Уменьшить declineCount
declineCount--;
} else {
acceptedCount--;
declinedCount++;
// Увеличить declineCount
declineCount++;
}
updateDisplayCounts();
localStorage.setItem('cellColors', JSON.stringify(cellColors));
updateAcceptanceRate();
}
}
}
function resetCount(type) {
if (type === 'accept') {
acceptCount = 0;
currentNumber = 1;
} else if (type === 'decline') {
//declineCount = 0;
acceptCount = 0;
currentNumber = 1;
declineCount = cellColors.filter(color => color === '#FF0000').length;
}
updateDisplayCounts();
// Очистка всех ячеек от текста
const cells = document.querySelectorAll('.cell');
cells.forEach((cell) => {
cell.textContent = '';
});
// Сохранение изменений в localStorage
localStorage.setItem('acceptCount', acceptCount);
localStorage.setItem('declineCount', declineCount);
localStorage.setItem('currentNumber', currentNumber);
localStorage.setItem('cellTexts', JSON.stringify(Array(100).fill('')));
}
window.onload = function() {
const cellsContainer = document.querySelector('.cells');
const cellTexts = JSON.parse(localStorage.getItem('cellTexts')) || Array(100).fill('');
for (let i = 0; i < cellColors.length; i++) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.id = `cell-${i}`;
cell.style.backgroundColor = cellColors[i];
cell.style.textAlign = 'center';
cell.textContent = cellTexts[i]; // Восстановление текста ячейки
//cell.onclick = () => toggleCellColor(i); // Установка обработчика клика
cell.addEventListener('click', () => toggleCellColor(i));
cellsContainer.appendChild(cell);
}
updateDisplayCounts();
updateAcceptanceRate();
document.getElementById('accept-count').addEventListener('click', () => {
acceptCount++;
updateDisplayCounts();
});
document.getElementById('decline-count').addEventListener('click', () => {
declineCount++;
updateDisplayCounts();
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(error => {
console.error('Service Worker registration failed:', error);
});
}
document.addEventListener('dblclick', function(event) {
event.preventDefault();
}, { passive: false });
function toggleLock() {
isLocked = true;
localStorage.setItem('isLocked', 'true');
const cells = document.querySelectorAll('.cell');
cells.forEach((cell) => {
cell.style.pointerEvents = 'none';
});
document.getElementById('toggle-switch').textContent = 'Unlock Cells';
}
function toggleUnLock() {
isLocked = false;
localStorage.setItem('isLocked', 'false');
const cells = document.querySelectorAll('.cell');
cells.forEach((cell) => {
cell.style.pointerEvents = 'auto';
});
document.getElementById('toggle-switch').textContent = 'Lock Cells';
}
document.getElementById('toggle-switch').addEventListener('click', () => {
if (isLocked) {
toggleUnLock();
} else {
toggleLock();
}
});
// Initial setup based on stored state
if (isLocked) {
toggleLock();
} else {
toggleUnLock();
}
};
// Анимация появления страницы
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
document.body.classList.remove('unloading');
}
setTimeout(function() {
document.body.classList.add('loaded');
}, 0);
});
document.getElementById('adjustmentButton').addEventListener('click', function() {
document.body.style.opacity = '0';
setTimeout(function() {
window.location.href = 'adjustment.html';
}, 300);
});