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

Матеріал з WikiLegalAid
мНемає опису редагування
Немає опису редагування
 
(Не показано 6 проміжних версій цього користувача)
Рядок 1: Рядок 1:
/* Розміщений тут код JavaScript буде завантажений всім користувачам при зверненні до будь-якої сторінки */
/* Розміщений тут код JavaScript буде завантажений всім користувачам при зверненні до будь-якої сторінки */
mw.loader.using('mediawiki.util').then(function () {
mw.loader.using('mediawiki.util').then(function () {
     if (mw.config.get('wgArticleId') !== 0) {
     if (mw.config.get('wgArticleId') !== 0) {
Рядок 69: Рядок 70:
         document.getElementById("consent-banner").style.display = "none";
         document.getElementById("consent-banner").style.display = "none";
     }
     }
});
mw.loader.using('mediawiki.util').then(function () {
  var ad = document.createElement('div');
  ad.setAttribute('align', 'center');
  ad.innerHTML = `
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234567890123456" crossorigin="anonymous"></script>
    <ins class="adsbygoogle"
        style="display:inline-block;width:728px;height:90px"
        data-ad-client="ca-pub-9946719691242357"
        data-ad-slot="1234567890"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
  `;
  // Додаємо перед основним контентом
  var content = document.getElementById('content');
  if (content) {
    content.parentNode.insertBefore(ad, content);
  }
});
});

Поточна версія на 14:21, 24 травня 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";
    }
});