Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

MediaWiki:Common.js: различия между версиями

Страница интерфейса MediaWiki
Новая страница: «mw.loader.getScript('https://www.googletagmanager.com/gtag/js?id=G-V4F3QK0W13').then(function() { window.dataLayer = window.dataLayer || []; window.gtag = function() { dataLayer.push(arguments); }; gtag('js', new Date()); gtag('config', 'G-V4F3QK0W13'); }); const formatTime = (seconds) => { if (isNaN(seconds)) return "0:00"; const m = Math.floor(seconds / 60); const s = Math.floor(seconds % 60); return m + ":" + (s < 10 ? "0" + s : s); }; d...»
Метка: Создано заново
 
Нет описания правки
 
Строка 8: Строка 8:
const formatTime = (seconds) => {
const formatTime = (seconds) => {
   if (isNaN(seconds)) return "0:00";
   if (isNaN(seconds)) return "0:00";
   const m = Math.floor(seconds / 60);
   const min = Math.floor(seconds / 60);
   const s = Math.floor(seconds % 60);
   const sec = Math.floor(seconds % 60);
   return m + ":" + (s < 10 ? "0" + s : s);
   return min + ":" + (sec < 10 ? "0" + sec : sec);
};
};



Текущая версия от 19:01, 13 апреля 2026

mw.loader.getScript('https://www.googletagmanager.com/gtag/js?id=G-V4F3QK0W13').then(function() {
  window.dataLayer = window.dataLayer || [];
  window.gtag = function() { dataLayer.push(arguments); };
  gtag('js', new Date());
  gtag('config', 'G-V4F3QK0W13');
});

const formatTime = (seconds) => {
  if (isNaN(seconds)) return "0:00";
  const min = Math.floor(seconds / 60);
  const sec = Math.floor(seconds % 60);
  return min + ":" + (sec < 10 ? "0" + sec : sec);
};

document.addEventListener('click', function(e) {
  if (e.target.classList.contains('wk-tab-btn')) {
    const container = e.target.closest('.wk-tabs-wrapper');
    const targetId = e.target.getAttribute('data-tab');
    container.querySelectorAll('.wk-tab-btn').forEach(btn => btn.classList.remove('active'));
    container.querySelectorAll('.wk-tab-content').forEach(content => content.classList.remove('active'));
    e.target.classList.add('active');
    const targetContent = container.querySelector('#' + targetId);
    if (targetContent) targetContent.classList.add('active');
  }
});

document.addEventListener('click', function(e) {
  const coverContainer = document.getElementById('cover-container');
  const imageLayer = document.getElementById('cover-image-layer');
  const videoLayer = document.getElementById('cover-video-layer');
  const inlineContainer = document.getElementById('inline-video-container');

  const playInlineBtn = e.target.closest('#inline-play-btn');
  const closeInlineBtn = e.target.closest('#close-inline-btn');
  const expandBtn = e.target.closest('#expand-btn');
  const muteBannerBtn = e.target.closest('#mute-btn');
  const closeBtn = e.target.closest('.modal-close');

  const loadVideo = (containerId, videoUrl, isModal) => {
    const container = document.getElementById(containerId);
    if (!container) return;

    if (!isModal) {
      container.innerHTML = `<video id="inline-vid" src="${videoUrl}" autoplay loop muted style="width: 100%; height: 100%; object-fit: cover; background-color: #000; outline: none; pointer-events: none;"></video>`;
      const muteIcon = document.getElementById('mute-icon');
      if (muteIcon) muteIcon.innerHTML = '<path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.73v2.06c2.89.86 5 3.54 5 6.67zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>';
    } else {
      container.innerHTML = `
        <div class="video-wrapper" style="position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: inherit; background: #000;">
          <video class="custom-video-player" src="${videoUrl}" autoplay loop style="width: 100%; height: 100%; object-fit: cover; outline: none; pointer-events: auto; cursor: pointer;"></video>
          <div class="wiki-center-action"></div>
          <div class="wiki-bottom-controls is-playing">
            <div class="wiki-progress-container">
              <div class="wiki-progress-bar">
                <div class="wiki-progress-loaded" style="width: 0%;"></div>
                <div class="wiki-progress-fill" style="width: 0%;"></div>
                <div class="wiki-progress-dot" style="left: 0%;"></div>
              </div>
            </div>
            <div class="wiki-controls-bar">
              <div class="wiki-ctrl-left">
                <button class="wiki-icon-btn wiki-play-pause">
                  <svg class="wiki-play-icon" viewBox="0 0 24 24" style="display:none;"><path d="M8 5v14l11-7z"/></svg>
                  <svg class="wiki-pause-icon" viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
                </button>
                <div class="wiki-volume-container">
                  <button class="wiki-icon-btn wiki-mute-btn">
                    <svg class="wiki-mute-off" viewBox="0 0 24 24" fill="currentColor" style="display:none;"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>
                    <svg class="wiki-mute-on" viewBox="0 0 24 24" fill="currentColor"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.73v2.06c2.89.86 5 3.54 5 6.67zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>
                  </button>
                  <input type="range" class="wiki-volume-slider" min="0" max="1" step="0.05" value="1">
                </div>
                <span class="wiki-time" style="color:#eee; font-size:13px; font-family:sans-serif; margin-left:5px;">0:00 / 0:00</span>
              </div>
              <div class="wiki-ctrl-right">
                <button class="wiki-icon-btn wiki-fullscreen-btn"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg></button>
              </div>
            </div>
          </div>
        </div>
      `;

      const videoWrapper = container.querySelector('.video-wrapper');
      const video = container.querySelector('.custom-video-player');
      const controls = container.querySelector('.wiki-bottom-controls');
      const timeDisplay = container.querySelector('.wiki-time');
      const progressFill = container.querySelector('.wiki-progress-fill');
      const progressLoaded = container.querySelector('.wiki-progress-loaded');
      const progressDot = container.querySelector('.wiki-progress-dot');
      const progressContainer = container.querySelector('.wiki-progress-container');
      const playPauseBtn = container.querySelector('.wiki-play-pause');
      const playIcon = container.querySelector('.wiki-play-icon');
      const pauseIcon = container.querySelector('.wiki-pause-icon');
      const muteBtn = container.querySelector('.wiki-mute-btn');
      const muteOn = container.querySelector('.wiki-mute-on');
      const muteOff = container.querySelector('.wiki-mute-off');
      const volumeSlider = container.querySelector('.wiki-volume-slider');
      const fullscreenBtn = container.querySelector('.wiki-fullscreen-btn');
      const centerAction = container.querySelector('.wiki-center-action');

      let lastVolume = 1;
      let idleTimer;

      const resetIdle = () => {
        videoWrapper.classList.remove('is-idle');
        clearTimeout(idleTimer);
        if (!video.paused) {
          idleTimer = setTimeout(() => videoWrapper.classList.add('is-idle'), 2000);
        }
      };

      videoWrapper.addEventListener('mousemove', resetIdle);
      videoWrapper.addEventListener('mousedown', resetIdle);
      videoWrapper.addEventListener('touchstart', resetIdle);
      controls.addEventListener('mouseenter', () => clearTimeout(idleTimer));
      controls.addEventListener('mouseleave', resetIdle);

      video.addEventListener('play', () => {
        controls.classList.add('is-playing');
        resetIdle();
      });
      video.addEventListener('pause', () => {
        controls.classList.remove('is-playing');
        clearTimeout(idleTimer);
        videoWrapper.classList.remove('is-idle');
      });

      const showCenterAction = (type) => {
        centerAction.innerHTML = type === 'play' ? '<svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>' : '<svg viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>';
        centerAction.classList.remove('animate');
        void centerAction.offsetWidth;
        centerAction.classList.add('animate');
        setTimeout(() => centerAction.classList.remove('animate'), 500);
      };

      const updateTime = () => {
        if (!video.duration) return;
        timeDisplay.textContent = formatTime(video.currentTime) + ' / ' + formatTime(video.duration);
        const percent = (video.currentTime / video.duration) * 100;
        progressFill.style.width = percent + '%';
        progressDot.style.left = percent + '%';
      };

      video.addEventListener('progress', () => {
        if (video.buffered.length > 0 && video.duration) {
          const bufferedEnd = video.buffered.end(video.buffered.length - 1);
          const percent = (bufferedEnd / video.duration) * 100;
          progressLoaded.style.width = percent + '%';
        }
      });

      video.addEventListener('timeupdate', updateTime);
      video.addEventListener('loadedmetadata', updateTime);

      progressContainer.addEventListener('click', (ev) => {
        ev.stopPropagation();
        const rect = progressContainer.getBoundingClientRect();
        video.currentTime = ((ev.clientX - rect.left) / rect.width) * video.duration;
      });

      const togglePlay = (ev) => {
        if (ev) ev.stopPropagation();
        if (video.paused) {
          video.play();
          playIcon.style.display = 'none';
          pauseIcon.style.display = 'block';
          showCenterAction('play');
        } else {
          video.pause();
          playIcon.style.display = 'block';
          pauseIcon.style.display = 'none';
          showCenterAction('pause');
        }
      };
      playPauseBtn.addEventListener('click', togglePlay);
      video.addEventListener('click', togglePlay);

      const updateMuteUI = () => {
        if (video.muted || video.volume === 0) {
          muteOn.style.display = 'block';
          muteOff.style.display = 'none';
        } else {
          muteOn.style.display = 'none';
          muteOff.style.display = 'block';
        }
      };

      volumeSlider.addEventListener('click', (ev) => ev.stopPropagation());
      volumeSlider.addEventListener('mousedown', (ev) => ev.stopPropagation());
      volumeSlider.addEventListener('input', (ev) => {
        ev.stopPropagation();
        video.volume = ev.target.value;
        video.muted = (video.volume == 0);
        updateMuteUI();
      });

      muteBtn.addEventListener('click', (ev) => {
        ev.stopPropagation();
        video.muted = !video.muted;
        if (video.muted) {
          lastVolume = video.volume || 1;
          video.volume = 0;
          volumeSlider.value = 0;
        } else {
          video.volume = lastVolume;
          volumeSlider.value = lastVolume;
        }
        updateMuteUI();
      });

      fullscreenBtn.addEventListener('click', (ev) => {
        ev.stopPropagation();
        if (!document.fullscreenElement) {
          if (videoWrapper.requestFullscreen) videoWrapper.requestFullscreen();
          else if (videoWrapper.webkitRequestFullscreen) videoWrapper.webkitRequestFullscreen();
          else if (videoWrapper.msRequestFullscreen) videoWrapper.msRequestFullscreen();
        } else {
          if (document.exitFullscreen) document.exitFullscreen();
          else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
          else if (document.msExitFullscreen) document.msExitFullscreen();
        }
      });
    }
  };

  if (playInlineBtn) {
    const videoUrl = coverContainer ? coverContainer.getAttribute('data-video-url') : null;
    if (!videoUrl) return;
    e.preventDefault();
    e.stopPropagation();
    imageLayer.style.display = 'none';
    videoLayer.style.display = 'flex';
    setTimeout(() => loadVideo('inline-video-container', videoUrl, false), 50);
    return;
  }

  if (muteBannerBtn) {
    e.preventDefault();
    e.stopPropagation();
    const video = document.getElementById('inline-vid');
    const muteIcon = document.getElementById('mute-icon');
    if (video) {
      video.muted = !video.muted;
      if (video.muted) {
        muteIcon.innerHTML = '<path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.73v2.06c2.89.86 5 3.54 5 6.67zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>';
      } else {
        muteIcon.innerHTML = '<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>';
      }
    }
    return;
  }

  if (closeInlineBtn) {
    e.preventDefault();
    e.stopPropagation();
    inlineContainer.innerHTML = '';
    videoLayer.style.display = 'none';
    imageLayer.style.display = 'flex';
    return;
  }

  if (expandBtn) {
    const videoUrl = coverContainer ? coverContainer.getAttribute('data-video-url') : null;
    if (!videoUrl) return;
    e.preventDefault();
    e.stopPropagation();
    
    inlineContainer.innerHTML = '';
    videoLayer.style.display = 'none';
    imageLayer.style.display = 'flex';
    
    let activeModal = document.getElementById('video-modal');
    if (!activeModal) {
      activeModal = document.createElement('div');
      activeModal.id = 'video-modal';
      activeModal.className = 'modal-overlay';
      activeModal.innerHTML = `<div class="modal-content"><span class="modal-close">&times;</span><div id="modal-video-container" style="width: 100%; height: 100%; position: relative;"></div></div>`;
      document.body.appendChild(activeModal);
    }
    activeModal.classList.add('active');
    activeModal.style.display = 'flex';
    document.body.style.overflow = 'hidden';
    setTimeout(() => loadVideo('modal-video-container', videoUrl, true), 50);
    return;
  }

  const activeModal = document.getElementById('video-modal');
  if (closeBtn || (activeModal && e.target === activeModal)) {
    e.preventDefault();
    e.stopPropagation();
    if (activeModal) {
      if (document.fullscreenElement) {
        if (document.exitFullscreen) document.exitFullscreen();
        else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
      }
      activeModal.classList.remove('active');
      activeModal.style.display = 'none';
    }
    document.body.style.overflow = '';
    const modalVidContainer = document.getElementById('modal-video-container');
    if (modalVidContainer) modalVidContainer.innerHTML = '';
  }
}, true);

mw.hook('wikipage.content').add(function($content) {
    const cards = $content[0].querySelectorAll('.server-card-minimal');
    if (cards.length === 0) return;

    if (window.serverMonitorInterval) {
        clearInterval(window.serverMonitorInterval);
    }

    function updateServers() {
        cards.forEach(card => {
            const serverId = card.getAttribute('data-server-id');
            const statusEl = card.querySelector('.server-status');
            const playersEl = card.querySelector('.server-players');
            const btnEl = card.querySelector('.server-connect-btn-minimal');

            if (!serverId) return;

            fetch(`/server_api.php?id=${serverId}`)
                .then(response => {
                    if (!response.ok) throw new Error('Ошибка сети: ' + response.status);
                    return response.json();
                })
                .then(data => {
                    if (data.online) {
                        statusEl.textContent = 'Онлайн';
                        statusEl.className = 'server-status status-online';
                        playersEl.textContent = data.players || '0/0';
                        if (btnEl) {
                            btnEl.href = `steam://connect/${data.ip}:${data.port}`;
                            btnEl.style.opacity = '1';
                            btnEl.style.pointerEvents = 'auto';
                        }
                    } else {
                        statusEl.textContent = 'Оффлайн';
                        statusEl.className = 'server-status status-offline';
                        playersEl.textContent = '-/-';
                        if (btnEl) {
                            btnEl.removeAttribute('href');
                            btnEl.style.opacity = '0.4';
                            btnEl.style.pointerEvents = 'none';
                        }
                    }
                })
                .catch(error => {
                    statusEl.textContent = 'Ошибка';
                    statusEl.className = 'server-status status-offline';
                    if (btnEl) {
                        btnEl.removeAttribute('href');
                        btnEl.style.opacity = '0.4';
                        btnEl.style.pointerEvents = 'none';
                    }
                });
        });
    }

    updateServers();

    window.serverMonitorInterval = setInterval(updateServers, 30000);
});