MediaWiki:Common.js: відмінності між версіями
Матеріал з WikiLegalAid
Alexb (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
Alexb (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
||
Рядок 75: | Рядок 75: | ||
function addMeta(property, content) { | function addMeta(property, content) { | ||
var meta = document.createElement("meta"); | if (content) { | ||
var meta = document.createElement("meta"); | |||
meta.setAttribute("property", property); | |||
meta.setAttribute("content", content); | |||
head.appendChild(meta); | |||
} | |||
} | } | ||
addMeta("og:title", mw.config.get("wgPageName").replace(/_/g, " ")); | |||
addMeta("og:title", | addMeta("og:type", "article"); | ||
addMeta("og:type", " | |||
addMeta("og:url", window.location.href); | addMeta("og:url", window.location.href); | ||
addMeta("og:image", "https://legalaid.wiki/images/logo.png"); | addMeta("og:image", "https://legalaid.wiki/images/logo.png"); // Вкажи реальний логотип | ||
addMeta("og:description", "Офіційна вікі сторінка | addMeta("og:description", "Офіційна вікі сторінка про правову допомогу"); | ||
addMeta("og:site_name", "Wiki Legal Aid"); | addMeta("og:site_name", "Wiki Legal Aid"); | ||
// Twitter Card | // Twitter Card | ||
addMeta("twitter:card", "summary_large_image"); | addMeta("twitter:card", "summary_large_image"); | ||
addMeta("twitter:title", | addMeta("twitter:title", mw.config.get("wgPageName").replace(/_/g, " ")); | ||
addMeta("twitter:description", "Офіційна вікі сторінка | addMeta("twitter:description", "Офіційна вікі сторінка про правову допомогу"); | ||
addMeta("twitter:image", "https://legalaid.wiki/images/logo.png"); | addMeta("twitter:image", "https://legalaid.wiki/images/logo.png"); | ||
}); | }); |
Версія за 18:21, 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";
}
});
mw.loader.using('mediawiki.util').then(function () {
var head = document.getElementsByTagName("head")[0];
function addMeta(property, content) {
if (content) {
var meta = document.createElement("meta");
meta.setAttribute("property", property);
meta.setAttribute("content", content);
head.appendChild(meta);
}
}
addMeta("og:title", mw.config.get("wgPageName").replace(/_/g, " "));
addMeta("og:type", "article");
addMeta("og:url", window.location.href);
addMeta("og:image", "https://legalaid.wiki/images/logo.png"); // Вкажи реальний логотип
addMeta("og:description", "Офіційна вікі сторінка про правову допомогу");
addMeta("og:site_name", "Wiki Legal Aid");
// Twitter Card
addMeta("twitter:card", "summary_large_image");
addMeta("twitter:title", mw.config.get("wgPageName").replace(/_/g, " "));
addMeta("twitter:description", "Офіційна вікі сторінка про правову допомогу");
addMeta("twitter:image", "https://legalaid.wiki/images/logo.png");
});