Aller au contenu

MediaWiki:Common.js

De Cat OPIDoR
Version datée du 23 avril 2026 à 14:32 par Administrateur (discussion | contributions)
(diff) ← Version précédente | Version actuelle (diff) | Version suivante → (diff)

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  •  Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */

/* Le code JavaScript pour la version mobile se trouve dans le fichier MediaWiki:Mobile.js */

function waitForCookieConsent(callback) {
  if (window.cookieConsent) {
    return callback();
  }
  return setTimeout(() => waitForCookieConsent(callback), 100);
}

waitForCookieConsent(() => {
  if (window.cookieConsent.isConsentGiven('statistics')) {
    initMatomo();
  } else {
    removeMatomo();
  }
});

function initMatomo() {
  window._paq = window._paq || [];
  const _paq = window._paq;

  _paq.push(['setDoNotTrack', false]);
  _paq.push(['rememberConsentGiven']);
  _paq.push(['setVisitorCookieTimeout', 33696000]);
  _paq.push(['setTrackerUrl', 'https://piwik2.inist.fr/piwik.php']);
  _paq.push(['setSiteId', '43']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);

  const d = document;
  const g = d.createElement('script');
  const s = d.getElementsByTagName('script')[0];

  g.type = 'text/javascript';
  g.async = true;
  g.defer = true;
  g.src = 'https://piwik2.inist.fr/piwik.js';
  g.id = 'matomo-script';
  s.parentNode.insertBefore(g, s);
}

function removeMatomo() {
  const script = document.getElementById('matomo-script');
  if (script) {
    script.remove();
  }

  document.cookie.split(';').forEach((cookie) => {
    const cookieName = cookie.split('=').at(0).trim();

    if (cookieName.startsWith('_pk_id') || cookieName.startsWith('_pk_ses') || cookieName === 'mtm_consent') {
      document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
    }
  });
}

function backtotop() {
  const place = document.querySelector('div.mw-page-container');
    const div = document.createElement('div');
    const link = document.createElement('a');

    div.setAttribute('class', 'back-to-top-wrapper');
    link.setAttribute('class', 'back-to-top-link');

    link.href = '#';
    link.appendChild(document.createTextNode('\u2b9d'));
    div.appendChild(link);

  place.append(div);
}
backtotop();