MediaWiki:Common.js: відмінності між версіями
Матеріал з WikiLegalAid
Alexb (обговорення | внесок) Створена сторінка: →Розміщений тут код JavaScript буде завантажений всім користувачам при зверненні до будь-якої сторінки: mw.loader.using('mediawiki.util').then(function () { if (mw.config.get('wgArticleId') !== 0) { $('.mw-footer').append('<p>Переглядів сторінки: ' + mw.config.get('wgPageViewCount') + '</p>'); } }); |
Alexb (обговорення | внесок) Немає опису редагування Мітка: Ручний відкіт |
||
(Не показано 9 проміжних версій цього користувача) | |||
Рядок 2: | Рядок 2: | ||
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) { | ||
$('.mw- | 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"; | |||
} | } | ||
}); | }); |
Поточна версія на 18:25, 7 березня 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";
}
});