MediaWiki:Common.js: відмінності між версіями
Матеріал з WikiLegalAid
Alexb (обговорення | внесок) Немає опису редагування Мітка: Ручний відкіт |
Alexb (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
||
| Рядок 69: | Рядок 69: | ||
document.getElementById("consent-banner").style.display = "none"; | document.getElementById("consent-banner").style.display = "none"; | ||
} | } | ||
}); | |||
mw.loader.using('mobile.startup', function () { | |||
mw.hook('wikipage.content').add(function ($content) { | |||
const adHtml = '<div class="ad-block" style="margin: 20px 0; text-align: center;">' + | |||
'<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-9946719691242357" data-ad-format="auto"></ins>' + | |||
'<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>' + | |||
'</div>'; | |||
$content.find('section').each(function () { | |||
const $section = $(this); | |||
const $heading = $section.find('h2, h3').first(); | |||
const $contentBlock = $section.find('.content').first(); | |||
$section.removeClass('collapsed'); | |||
$section.addClass('expanded'); | |||
$contentBlock.show(); | |||
$section.after(adHtml); | |||
}); | |||
}); | |||
}); | }); | ||
Версія за 09:08, 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('wikipage.content').add(function ($content) {
const adHtml = '<div class="ad-block" style="margin: 20px 0; text-align: center;">' +
'<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-9946719691242357" data-ad-format="auto"></ins>' +
'<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>' +
'</div>';
$content.find('section').each(function () {
const $section = $(this);
const $heading = $section.find('h2, h3').first();
const $contentBlock = $section.find('.content').first();
$section.removeClass('collapsed');
$section.addClass('expanded');
$contentBlock.show();
$section.after(adHtml);
});
});
});
