Tess Thomson Videos
Best rated videos
4.5К
4.7
Feb 19, 2026
15.4К
5
Feb 08, 2026
486
5
Feb 16, 2026
927
3
Feb 13, 2026
331
3
Feb 16, 2026
2.2К
5
Feb 05, 2026
Список пуст
`;
if (pagination) pagination.style.display = "none";
updateClearButton();
updateCounter();
return true;
}
return false;
}
// --- Обновить счётчик ---
function updateCounter() {
const counter = document.getElementById("watchlater-counter");
if (!counter) return;
const lists = getAllLists();
const list = lists[currentListName] || [];
counter.textContent = list.length > 0 ? `(${list.length})` : "";
}
// --- Обновить видимость кнопки "Очистить всё" ---
function updateClearButton() {
const btn = document.getElementById("clear-watchlater");
if (!btn) return;
const lists = getAllLists();
const list = lists[currentListName] || [];
btn.style.display = list.length > 0 ? "inline-flex" : "none";
updateCounter();
}
// --- Загрузка элементов для текущей страницы ---
function loadPage(page, listName = currentListName) {
currentListName = listName;
wl_current_page = page;
const lists = getAllLists();
const list = lists[listName] || [];
const container = document.getElementById("watchlater-list");
const pagination = document.getElementById("watchlater-pagination");
if (!container) return;
container.innerHTML = `Загрузка...
`;
const start = (page - 1) * wl_per_page;
const end = start + wl_per_page;
const ids = list.slice(start, end);
if (ids.length === 0) {
container.innerHTML = `Список пуст
`;
if (pagination) pagination.style.display = "none";
return;
}
fetch(`/index.php?do=watchlater&ids=${ids.join(",")}&ajax=1`)
.then(r => {
if (!r.ok) throw new Error(`HTTP error! status: ${r.status}`);
return r.text();
})
.then(html => {
container.innerHTML = html;
initWatchLaterButtons();
updateClearButton();
updatePagination();
$('img[data-preview]').videopreview();
})
.catch(e => {
console.error("Ошибка загрузки данных:", e);
container.innerHTML = `Ошибка загрузки данных. Попробуйте позже.
`;
});
}
// --- Обновление пагинации ---
function updatePagination() {
const lists = getAllLists();
const list = lists[currentListName] || [];
wl_total_pages = Math.ceil(list.length / wl_per_page);
const pagination = document.getElementById("watchlater-pagination");
if (!pagination) return;
if (wl_total_pages <= 1) {
pagination.style.display = "none";
return;
}
let html = `
`;
for (let i = 1; i <= wl_total_pages; i++) {
if (i === wl_current_page) {
html += `${i}`;
} else {
html += `${i}`;
}
}
html += `
${name} (${items.length})
`;
}
container.innerHTML = html;
// Обработчики для кнопок
document.querySelectorAll(".rename-list").forEach(btn => {
btn.addEventListener("click", (e) => {
const name = e.target.dataset.name;
const newName = prompt("Новое имя:", name);
if (newName && newName !== name) {
renameList(name, newName);
renderListsModal();
if (currentListName === name) {
currentListName = newName;
}
}
});
});
document.querySelectorAll(".delete-list").forEach(btn => {
btn.addEventListener("click", (e) => {
const name = e.target.dataset.name;
if (confirm(`Удалить список "${name}"?`)) {
deleteList(name);
renderListsModal();
if (currentListName === name) {
currentListName = "default";
loadPage(1, "default");
}
}
});
});
document.querySelectorAll(".switch-list").forEach(btn => {
btn.addEventListener("click", (e) => {
const name = e.target.dataset.name;
switchList(name);
document.getElementById("lists-modal").style.display = "none";
});
});
}
// --- Инициализация страницы Watch Later ---
function initWatchLaterPage() {
if (!location.pathname.includes("watchlater")) return;
// Кнопка для открытия модального окна списков
const openListsModalBtn = document.createElement("button");
openListsModalBtn.id = "open-lists-modal";
openListsModalBtn.textContent = "Мои списки";
openListsModalBtn.style.marginLeft = "10px";
document.querySelector(".page-header").appendChild(openListsModalBtn);
// Кнопка "Очистить всё"
const clearBtn = document.getElementById("clear-watchlater");
if (clearBtn) {
clearBtn.addEventListener("click", clearCurrentList);
}
// Загружаем первый список
loadPage(1, "default");
}
// --- Обработчики событий ---
document.addEventListener("click", function(e) {
// Удаление видео из списка
let btn = e.target.closest(".watchlater-btn");
if (btn) {
let id = Number(btn.dataset.id);
let card = btn.closest("div.col");
if (card) {
card.style.transition = "opacity .3s";
card.style.opacity = "0";
setTimeout(() => {
card.remove();
removeFromList(currentListName, id);
const lists = getAllLists();
const list = lists[currentListName] || [];
if (list.length === 0) {
showEmptyIfNeeded();
} else {
loadPage(wl_current_page, currentListName);
}
}, 300);
}
}
// Открытие модального окна списков
const openListsModalBtn = e.target.closest("#open-lists-modal");
if (openListsModalBtn) {
document.getElementById("lists-modal").style.display = "block";
renderListsModal();
}
// Закрытие модального окна
const closeListsModalBtn = e.target.closest("#close-lists-modal");
if (closeListsModalBtn) {
document.getElementById("lists-modal").style.display = "none";
}
// Создание нового списка
const createListBtn = e.target.closest("#create-list-btn");
if (createListBtn) {
const name = document.getElementById("new-list-name").value.trim();
if (name) {
createNewList(name);
document.getElementById("new-list-name").value = "";
renderListsModal();
}
}
});
// --- Запуск при загрузке страницы ---
document.addEventListener("DOMContentLoaded", function() {
initWatchLaterPage();
});
${name !== "default" ? `` : ""}