Описание:
Этот JavaScript-скрипт предназначен для форумов на платформе MyBB. Он выполняет автоматическую проверку статуса посетителя (гость или авторизованный пользователь) и отображает специальное модальное окно для неавторизованных пользователей.
Если посетитель идентифицирован как гость:
Создается полупрозрачный оверлей, блокирующий доступ к содержимому
Отображается информационное окно с требованием авторизации
Предоставляются кнопки для входа или регистрации на форуме
ВАЖНО: Добавлять в верх форума
Код:<script> setTimeout(function() { var isGuest = true; var logoutLink = document.querySelector('a[href*="logout"], a[href*="action=logout"]'); if (logoutLink) { isGuest = false; } var usernameElements = document.querySelectorAll('.username, .usertitle, .welcome strong, #userinfo strong'); if (usernameElements.length > 0) { for (var i = 0; i < usernameElements.length; i++) { var text = usernameElements[i].textContent.trim().toLowerCase(); if (text && text !== 'гость' && text !== 'guest' && !text.includes('guest')) { isGuest = false; break; } } } var punStatus = document.getElementById('pun-status'); if (punStatus) { var statusText = punStatus.innerHTML.toLowerCase(); if (statusText.indexOf('гость') === -1 && statusText.indexOf('guest') === -1) { isGuest = false; } } var loginButton = document.querySelector('a[href*="login"][href*="member.php"], a[href*="action=login"]'); var hasLoginButton = !!loginButton; if (logoutLink || (!hasLoginButton && usernameElements.length > 0)) { isGuest = false; } console.log('Проверка гостя:', { isGuest: isGuest, logoutLink: !!logoutLink, usernameElements: usernameElements.length, punStatus: !!punStatus, loginButton: hasLoginButton }); if (isGuest) { var overlay = document.createElement('div'); overlay.id = 'guest-overlay'; overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.85);z-index:99999;display:flex;justify-content:center;align-items:center;'; var modal = document.createElement('div'); modal.style.cssText = 'background:#2c3e50;color:white;padding:30px;border-radius:10px;text-align:center;max-width:500px;width:80%;border:2px solid #3498db;position:relative;'; var title = document.createElement('h3'); title.textContent = 'Требуется авторизация'; title.style.cssText = 'color:#3498db;margin-bottom:15px;font-size:24px;'; var message = document.createElement('p'); message.innerHTML = 'Пожалуйста зарегистрируйтесь или войдите в свой профиль.<br>В режиме гостя форум невозможно просмотреть.'; message.style.cssText = 'margin-bottom:20px;font-size:18px;line-height:1.5;'; var buttons = document.createElement('div'); buttons.style.cssText = 'display:flex;justify-content:center;gap:15px;flex-wrap:wrap;'; var loginBtn = document.createElement('a'); loginBtn.href = 'https://vicemultiplayer.mybb.ru/login.php'; loginBtn.textContent = 'Войти'; loginBtn.style.cssText = 'background:#3498db;color:white;padding:12px 25px;border-radius:5px;text-decoration:none;font-weight:bold;font-size:16px;transition:all 0.3s;display:inline-block;'; loginBtn.onmouseover = function() { this.style.background = '#2980b9'; this.style.transform = 'scale(1.05)'; }; loginBtn.onmouseout = function() { this.style.background = '#3498db'; this.style.transform = 'scale(1)'; }; var registerBtn = document.createElement('a'); registerBtn.href = 'https://vicemultiplayer.mybb.ru/register.php'; registerBtn.textContent = 'Зарегистрироваться'; registerBtn.style.cssText = 'background:#2ecc71;color:white;padding:12px 25px;border-radius:5px;text-decoration:none;font-weight:bold;font-size:16px;transition:all 0.3s;display:inline-block;'; registerBtn.onmouseover = function() { this.style.background = '#27ae60'; this.style.transform = 'scale(1.05)'; }; registerBtn.onmouseout = function() { this.style.background = '#2ecc71'; this.style.transform = 'scale(1)'; }; buttons.appendChild(loginBtn); buttons.appendChild(registerBtn); modal.appendChild(title); modal.appendChild(message); modal.appendChild(buttons); overlay.appendChild(modal); document.body.appendChild(overlay); document.body.style.overflow = 'hidden'; overlay.onclick = function(e) { if (e.target === overlay) { if (confirm('Вы действительно хотите закрыть это окно? Без регистрации доступ к форуму ограничен.')) { overlay.remove(); document.body.style.overflow = 'auto'; } } }; } }, 2000); </script>
[good]
