-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
189 lines (165 loc) · 7.22 KB
/
script.js
File metadata and controls
189 lines (165 loc) · 7.22 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
// Общие функции для всего сайта
// Функция для надежной загрузки изображений через data URL
function loadImageWithRetry(imgElement, url, maxRetries = 3) {
let retryCount = 0;
function attemptLoad() {
if (retryCount >= maxRetries) {
console.log(`Не удалось загрузить изображение после ${maxRetries} попыток: ${url}`);
imgElement.onerror = null;
if (imgElement.classList.contains('img-loading')) {
imgElement.classList.remove('img-loading');
}
imgElement.src = 'no-poster.png';
return;
}
retryCount++;
const tempImg = new Image();
tempImg.crossOrigin = 'anonymous';
tempImg.onload = function() {
try {
const canvas = document.createElement('canvas');
canvas.width = tempImg.naturalWidth;
canvas.height = tempImg.naturalHeight;
const ctx = canvas.getContext('2d');
ctx.drawImage(tempImg, 0, 0);
const dataUrl = canvas.toDataURL('image/jpeg', 0.9);
imgElement.src = dataUrl;
imgElement.onerror = null;
if (imgElement.classList.contains('img-loading')) {
imgElement.classList.remove('img-loading');
}
console.log(`Изображение успешно загружено через data URL (попытка ${retryCount})`);
} catch (error) {
console.log(`Ошибка конвертации в data URL, попытка ${retryCount}:`, error);
if (retryCount < maxRetries) {
setTimeout(attemptLoad, 1000 * retryCount);
} else {
if (imgElement.classList.contains('img-loading')) {
imgElement.classList.remove('img-loading');
}
imgElement.src = 'no-poster.png';
}
}
};
tempImg.onerror = function() {
console.log(`Ошибка загрузки временного изображения, попытка ${retryCount}: ${url}`);
if (retryCount < maxRetries) {
setTimeout(attemptLoad, 1000 * retryCount);
} else {
if (imgElement.classList.contains('img-loading')) {
imgElement.classList.remove('img-loading');
}
imgElement.src = 'no-poster.png';
}
};
tempImg.src = url + (url.includes('?') ? '&' : '?') + 'retry=' + Date.now();
}
attemptLoad();
}
// Функция для создания img элемента с надежной загрузкой
function createReliableImage(url, alt, className = '') {
const img = document.createElement('img');
img.alt = alt || '';
if (className) img.className = className;
// Устанавливаем прозрачный пиксель как заглушку
img.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PC9zdmc+';
img.style.backgroundColor = '#2a2a2a';
img.classList.add('img-loading');
// Загружаем изображение через data URL если URL валидный
if (url && url !== 'no-poster.png' && url.startsWith('http')) {
loadImageWithRetry(img, url);
} else {
img.src = 'no-poster.png';
img.classList.remove('img-loading');
}
return img;
}
// Функция для форматирования времени из секунд
function formatRuntime(seconds) {
if (!seconds) return '';
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}ч ${minutes}м`;
}
// Функция для получения параметра из URL
function getUrlParam(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// Функция для показа уведомления
function showNotification(message, type = 'info') {
// Создаем контейнер для уведомлений если его нет
let notificationContainer = document.getElementById('notification-container');
if (!notificationContainer) {
notificationContainer = document.createElement('div');
notificationContainer.id = 'notification-container';
notificationContainer.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
`;
document.body.appendChild(notificationContainer);
}
// Создаем уведомление
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.innerHTML = `
<div class="notification-content">${message}</div>
<button class="notification-close">×</button>
`;
// Стили для уведомления
notification.style.cssText = `
background-color: ${type === 'error' ? '#4a0000' : type === 'success' ? '#004a00' : '#222'};
color: #eee;
padding: 15px 20px;
margin-bottom: 10px;
border-radius: 8px;
border: 2px solid ${type === 'error' ? '#ff4444' : type === 'success' ? '#44ff44' : '#4B0082'};
display: flex;
justify-content: space-between;
align-items: center;
min-width: 300px;
max-width: 400px;
animation: slideIn 0.3s ease;
`;
// Стили для кнопки закрытия
const closeBtn = notification.querySelector('.notification-close');
closeBtn.style.cssText = `
background: none;
border: none;
color: #eee;
font-size: 20px;
cursor: pointer;
padding: 0;
margin-left: 15px;
`;
closeBtn.addEventListener('click', () => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
});
// Автоматическое удаление через 5 секунд
setTimeout(() => {
if (notification.parentNode) {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}
}, 5000);
notificationContainer.appendChild(notification);
// Добавляем CSS анимации
if (!document.querySelector('#notification-styles')) {
const style = document.createElement('style');
style.id = 'notification-styles';
style.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
`;
document.head.appendChild(style);
}
}