MediaWiki:Common.js: Difference between revisions

From Zezenia Online Wiki
Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: var css = document.createElement("link"); css.rel = "stylesheet"; css.type = "text/css"; css.href =..."
 
Remove
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/* Google Analytics */
var gtm = document.createElement("script");
gtm.async = true;
gtm.src = "https://www.googletagmanager.com/gtag/js?id=G-Z2TDHQE12Q";
gtm.setAttribute("type", "text/plain");
gtm.setAttribute("data-zezenia-consent", "analytics");
document.body.appendChild(gtm);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Z2TDHQE12Q');
/* Plausible */
var script = document.createElement('script');
script.setAttribute('data-domain', 'account.playzezenia.com');
script.setAttribute('data-zezenia-consent', 'functional');
script.setAttribute('type', 'text/plain');
script.setAttribute('src', 'https://plausible.io/js/plausible.js');
document.head.appendChild(script);
/* Consent */
var css = document.createElement("link");
var css = document.createElement("link");
css.rel = "stylesheet";
css.rel = "stylesheet";
css.type = "text/css";
css.type = "text/css";
css.href = "https://www.playzezenia.com/cdn/styles/cookieconsent.css";
css.href = "https://consent.playzezenia.com/consent.css";
document.head.appendChild(css);
document.head.appendChild(css);


var script = document.createElement("script");
var script = document.createElement("script");
script.src = "https://www.playzezenia.com/cdn/js/cookieconsent.js";
script.src = "https://consent.playzezenia.com/consent.js";
script.async = true;
script.async = true;
script.onload = function() {
document.body.appendChild(script);
window.cookieconsent.initialise({
 
palette: {
/* Embed maps */
popup: {
  var embeds = document.querySelectorAll(".zezenia-map-embed");
background: "#000",
  embeds.forEach(function(embed) {
text: "#ececec"
    var iframe = document.createElement("iframe");
},
    iframe.width = embed.dataset.width || 800;
button: {
    iframe.height = embed.dataset.height || 600;
background: "#fff",
 
text: "#000"
    var params = "embed=true&";
}
    if (embed.dataset.x) params += "x=" + embed.dataset.x + "&";
},
    if (embed.dataset.y) params += "y=" + embed.dataset.y + "&";
content: {
    if (embed.dataset.z) params += "z=" + embed.dataset.z + "&";
message: "Zezenia Online uses cookies to log you in and improve our services.",
    if (embed.dataset.zoom) params += "zoom=" + embed.dataset.zoom + "&";
dismiss: "I agree",
    if (embed.dataset.center) params += "center=" + embed.dataset.center + "&";
link: "Privacy Policy",
    if (embed.dataset.markers) params += "markers=" + encodeURIComponent(embed.dataset.markers) + "&";
href: "https://www.playzezenia.com/home/legal#2",
    if (embed.dataset.nobuiltins && embed.dataset.nobuiltins.length) params += "hidemarkers=true&";
},
    iframe.src = "https://map.playzezenia.com?" + params;
cookie: {
 
domain: "." + document.domain.split('.').reverse().splice(0, 2).reverse().join('.'),
    embed.appendChild(iframe);
},
  });
 
/* Toggle maps */
var toggleMaps = document.querySelectorAll(".zezenia-map-toggle");
toggleMaps.forEach(function(toggle) {
  toggle.style.display = "inline-block";
 
  var map = toggle.querySelector(".zezenia-map-embed");
  map.style.display = "none";
 
  var link = document.createElement("a");
  link.innerText = "🗺️ Open map";
  link.onclick = function(e) {
    e.preventDefault();
 
    if (map.style.display !== "none") {
      map.style.display = "none";
      link.innerHTML = "🗺️ Open map";
    } else {
      map.style.display = "block";
      link.innerHTML = "🗺️ Close map";
    }
 
    return false;
  };
  link.href = "#";
 
  toggle.insertBefore(link, map);
});
});
}
 
document.body.appendChild(script);
/* Remember spoiler toggle */
setTimeout(function() {
  var toggles = document.querySelectorAll('.mw-collapsible a.mw-collapsible-text');
  Array.from(toggles).forEach(function(toggle) {
    toggle.addEventListener('click', function() {
      setTimeout(function() {
        var expanded = toggle.parentNode.className.indexOf('expanded') >= 0;
        window.localStorage['zezenia-spoilers'] = expanded;
      });
    });
  });
 
  if (window.localStorage['zezenia-spoilers'] === 'true') {
    Array.from(toggles).forEach(function(toggle) {
      if (toggle.parentNode.className.indexOf('expanded') === -1) {
        toggle.click();
      }
    });
  }
}, 100);

Latest revision as of 10:43, 30 September 2023

/* Any JavaScript here will be loaded for all users on every page load. */

/* Google Analytics */
var gtm = document.createElement("script");
gtm.async = true;
gtm.src = "https://www.googletagmanager.com/gtag/js?id=G-Z2TDHQE12Q";
gtm.setAttribute("type", "text/plain");
gtm.setAttribute("data-zezenia-consent", "analytics");
document.body.appendChild(gtm);

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Z2TDHQE12Q');

/* Plausible */
var script = document.createElement('script');
script.setAttribute('data-domain', 'account.playzezenia.com');
script.setAttribute('data-zezenia-consent', 'functional');
script.setAttribute('type', 'text/plain');
script.setAttribute('src', 'https://plausible.io/js/plausible.js');
document.head.appendChild(script);

/* Consent */
var css = document.createElement("link");
css.rel = "stylesheet";
css.type = "text/css";
css.href = "https://consent.playzezenia.com/consent.css";
document.head.appendChild(css);

var script = document.createElement("script");
script.src = "https://consent.playzezenia.com/consent.js";
script.async = true;
document.body.appendChild(script);

/* Embed maps */
  var embeds = document.querySelectorAll(".zezenia-map-embed");
  embeds.forEach(function(embed) {
    var iframe = document.createElement("iframe");
    iframe.width = embed.dataset.width || 800;
    iframe.height = embed.dataset.height || 600;

    var params = "embed=true&";
    if (embed.dataset.x) params += "x=" + embed.dataset.x + "&";
    if (embed.dataset.y) params += "y=" + embed.dataset.y + "&";
    if (embed.dataset.z) params += "z=" + embed.dataset.z + "&";
    if (embed.dataset.zoom) params += "zoom=" + embed.dataset.zoom + "&";
    if (embed.dataset.center) params += "center=" + embed.dataset.center + "&";
    if (embed.dataset.markers) params += "markers=" + encodeURIComponent(embed.dataset.markers) + "&";
    if (embed.dataset.nobuiltins && embed.dataset.nobuiltins.length) params += "hidemarkers=true&";
    iframe.src = "https://map.playzezenia.com?" + params;

    embed.appendChild(iframe);
  });

/* Toggle maps */
var toggleMaps = document.querySelectorAll(".zezenia-map-toggle");
toggleMaps.forEach(function(toggle) {
  toggle.style.display = "inline-block";

  var map = toggle.querySelector(".zezenia-map-embed");
  map.style.display = "none";

  var link = document.createElement("a");
  link.innerText = "🗺️ Open map";
  link.onclick = function(e) {
    e.preventDefault();

    if (map.style.display !== "none") {
      map.style.display = "none";
      link.innerHTML = "🗺️ Open map";
    } else {
      map.style.display = "block";
      link.innerHTML = "🗺️ Close map";
    }

    return false;
  };
  link.href = "#";

  toggle.insertBefore(link, map);
});

/* Remember spoiler toggle */
setTimeout(function() {
  var toggles = document.querySelectorAll('.mw-collapsible a.mw-collapsible-text');
  Array.from(toggles).forEach(function(toggle) {
    toggle.addEventListener('click', function() {
      setTimeout(function() {
        var expanded = toggle.parentNode.className.indexOf('expanded') >= 0;
        window.localStorage['zezenia-spoilers'] = expanded;
      });
    });
  });
  
  if (window.localStorage['zezenia-spoilers'] === 'true') {
    Array.from(toggles).forEach(function(toggle) {
      if (toggle.parentNode.className.indexOf('expanded') === -1) {
        toggle.click();
      }
    });
  }
}, 100);