MediaWiki:Common.js: відмінності між версіями

Матеріал з WikiLegalAid
Немає опису редагування
Мітка: Скасовано
Немає опису редагування
Мітка: Скасовано
Рядок 72: Рядок 72:


mw.loader.using('mobile.startup', function () {
mw.loader.using('mobile.startup', function () {
    mw.hook('wikipage.content').add(function ($content) {
  mw.hook('mobile.sectionToggle.loaded').add(function () {
        const adHtml = '<div class="ad-block" style="margin: 20px 0; text-align: center;">' +
    // Всі розділи готові — знімаємо collapse і вставляємо рекламу
                      '<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-9946719691242357" data-ad-format="auto"></ins>' +
    document.querySelectorAll('section.collapsed').forEach(function (section) {
                      '<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>' +
      section.classList.remove('collapsed');
                      '</div>';
      section.classList.add('expanded');


        $content.find('section').each(function () {
      const content = section.querySelector('.content');
       const $section = $(this);
       if (content) {
      const $heading = $section.find('h2, h3').first();
        content.style.display = 'block';
       const $contentBlock = $section.find('.content').first();
       }


      // Додаємо рекламний блок
      const adDiv = document.createElement('div');
      adDiv.className = 'ad-block';
      adDiv.style = 'margin: 20px 0; text-align: center;';
      adDiv.innerHTML = '<ins class="adsbygoogle" style="display:block" data-ad-client="ca‑pub‑9946719691242357" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>';


       $section.removeClass('collapsed');
       section.after(adDiv);
      $section.addClass('expanded');
 
 
      $contentBlock.show();
 
 
      $section.after(adHtml);
        });
     });
     });
  });
});
});

Версія за 09:29, 12 травня 2025

/* Розміщений тут код JavaScript буде завантажений всім користувачам при зверненні до будь-якої сторінки */
mw.loader.using('mediawiki.util').then(function () {
    if (mw.config.get('wgArticleId') !== 0) {
        var pageViews = mw.config.get('wgHitcounter'); // Використовуємо HitCounters

        // Вставити кількість переглядів у заголовок сторінки
        if (pageViews !== null && pageViews !== undefined) {
            $('.mw-first-heading').append('<span style="font-size: 14px; color: gray; margin-left: 10px;">(Переглядів: ' + pageViews + ')</span>');
        } else {
            $('.mw-first-heading').append('<span style="font-size: 14px; color: gray; margin-left: 10px;">(Переглядів: немає даних)</span>');
        }
    }
});

mw.loader.using('mediawiki.util').then(function () {
    var heading = document.querySelector("h1.firstHeading .mw-page-title-main");
    if (heading) {
        var logo = document.createElement("img");
        logo.src = "/images/logo.png";
        logo.classList.add("page-title-logo");

        heading.prepend(logo);
    }
});


window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied',
    'functionality_storage': 'granted',
    'personalization_storage': 'denied',
    'security_storage': 'granted'
});

document.addEventListener("DOMContentLoaded", function() {
    var consentBanner = document.createElement('div');
    consentBanner.innerHTML = `
        <div id="consent-banner" style="position: fixed; bottom: 10px; left: 10px; right: 10px; background: white; border: 1px solid gray; padding: 15px; z-index: 1000; text-align: center;">
            <p>Ми використовуємо файли cookie для персоналізації реклами та аналітики. Продовжуючи користуватися сайтом, ви даєте згоду на використання cookie.</p>
            <button id="accept-cookies" style="padding: 10px; margin: 5px; background: green; color: white; border: none;">Прийняти</button>
            <button id="decline-cookies" style="padding: 10px; margin: 5px; background: red; color: white; border: none;">Відмовитися</button>
        </div>
    `;
    document.body.appendChild(consentBanner);

    document.getElementById("accept-cookies").addEventListener("click", function() {
        gtag('consent', 'update', {
            'ad_storage': 'granted',
            'analytics_storage': 'granted',
            'personalization_storage': 'granted'
        });
        document.getElementById("consent-banner").style.display = "none";
        localStorage.setItem("cookieConsent", "granted");
    });

    document.getElementById("decline-cookies").addEventListener("click", function() {
        gtag('consent', 'update', {
            'ad_storage': 'denied',
            'analytics_storage': 'denied',
            'personalization_storage': 'denied'
        });
        document.getElementById("consent-banner").style.display = "none";
        localStorage.setItem("cookieConsent", "denied");
    });

    if (localStorage.getItem("cookieConsent")) {
        document.getElementById("consent-banner").style.display = "none";
    }
});

mw.loader.using('mobile.startup', function () {
  mw.hook('mobile.sectionToggle.loaded').add(function () {
    // Всі розділи готові — знімаємо collapse і вставляємо рекламу
    document.querySelectorAll('section.collapsed').forEach(function (section) {
      section.classList.remove('collapsed');
      section.classList.add('expanded');

      const content = section.querySelector('.content');
      if (content) {
        content.style.display = 'block';
      }

      // Додаємо рекламний блок
      const adDiv = document.createElement('div');
      adDiv.className = 'ad-block';
      adDiv.style = 'margin: 20px 0; text-align: center;';
      adDiv.innerHTML = '<ins class="adsbygoogle" style="display:block" data-ad-client="ca‑pub‑9946719691242357" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>';

      section.after(adDiv);
    });
  });
});