Tess Thomson
Videos

Best rated videos

A place for those who want to find girls for online sex

Free Live Sex Cams!

// =============================== // СКРИПТ ТОЛЬКО ДЛЯ СТРАНИЦЫ WATCHLATER // =============================== // --- Глобальные переменные --- let currentListName = "default"; let wl_current_page = 1; let wl_per_page = 12; let wl_total_pages = 0; // --- Получение всех списков --- function getAllLists() { try { const lists = JSON.parse(localStorage.getItem("watchlater_lists") || "{}"); if (!lists.default) lists.default = []; return lists; } catch (e) { console.error("Ошибка чтения списков:", e); return { default: [] }; } } // --- Сохранение всех списков --- function saveAllLists(lists) { try { localStorage.setItem("watchlater_lists", JSON.stringify(lists)); } catch (e) { console.error("Ошибка сохранения списков:", e); } } // --- Показать сообщение "Список пуст" --- function showEmptyIfNeeded() { const container = document.getElementById("watchlater-list"); const pagination = document.getElementById("watchlater-pagination"); const lists = getAllLists(); const list = lists[currentListName] || []; if (list.length === 0) { container.innerHTML = `
Список пуст
`; 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 = `
${wl_current_page > 1 ? `<` : `<`}
`; for (let i = 1; i <= wl_total_pages; i++) { if (i === wl_current_page) { html += `${i}`; } else { html += `${i}`; } } html += `
${wl_current_page < wl_total_pages ? `>` : `>`}
`; pagination.innerHTML = html; pagination.querySelectorAll('a.btn, span.btn').forEach(btn => { if (!btn.classList.contains('disabled')) { btn.addEventListener('click', (e) => { e.preventDefault(); const page = parseInt(e.target.dataset.page); loadPage(page, currentListName); }); } }); pagination.style.display = "block"; } // --- Создание нового списка --- function createNewList(name) { const lists = getAllLists(); if (lists[name]) { alert("Список с таким именем уже существует!"); return false; } lists[name] = []; saveAllLists(lists); return true; } // --- Переименование списка --- function renameList(oldName, newName) { const lists = getAllLists(); if (!lists[oldName] || lists[newName]) { alert("Некорректное имя списка!"); return false; } lists[newName] = lists[oldName]; delete lists[oldName]; saveAllLists(lists); return true; } // --- Удаление списка --- function deleteList(name) { if (name === "default") { alert("Нельзя удалить стандартный список!"); return false; } const lists = getAllLists(); if (!lists[name]) { alert("Список не найден!"); return false; } delete lists[name]; saveAllLists(lists); return true; } // --- Очистка текущего списка --- function clearCurrentList() { if (!confirm("Очистить весь список?")) return; const lists = getAllLists(); lists[currentListName] = []; saveAllLists(lists); loadPage(1, currentListName); } // --- Переключение на другой список --- function switchList(listName) { currentListName = listName; wl_current_page = 1; loadPage(1, listName); updateClearButton(); updateCounter(); } // --- Отображение модального окна управления списками --- function renderListsModal() { const lists = getAllLists(); const container = document.getElementById("lists-list"); if (!container) return; let html = ""; for (const [name, items] of Object.entries(lists)) { html += `
${name} (${items.length})
${name !== "default" ? `` : ""}
`; } 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(); });