« MediaWiki:Common.js » : différence entre les versions
(Contenu remplacé par « →Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. : $( function () { var elems = document.getElementsByClassName('mw-e… ») Balise : Contenu remplacé |
(Annulation des modifications 116001 de Shumz (discussion)) Balise : Annulation |
||
Ligne 14 : | Ligne 14 : | ||
} | } | ||
}); | }); | ||
/** | |||
* Author and copyright: Stefan Haack (https://shaack.com) | |||
* Repository: https://github.com/shaack/cookie-consent-js | |||
* License: MIT, see file 'LICENSE' | |||
*/ | |||
function CookieConsent(props) { | |||
var self = this | |||
this.props = { | |||
buttonPrimaryClass: "btn btn-primary", // the "accept all" buttons class, only used for styling | |||
buttonSecondaryClass: "btn btn-secondary", // the "accept necessary" buttons class, only used for styling | |||
privacyPolicyUrl: "privacy-policy.html", | |||
autoShowModal: true, // disable autoShowModal on the privacy policy page, to make that page readable | |||
lang: "en", // the language, in which the modal is shown | |||
blockAccess: false, // set "true" to block the access to the website _before_ choosing a cookie configuration | |||
position: "right", // position ("left" or "right"), if blockAccess is false | |||
postSelectionCallback: undefined, // callback, after the user has made his selection | |||
content: { // the content in all needed languages | |||
de: { | |||
title: "Cookie-Einstellungen", | |||
body: "Wir nutzen Cookies, um Inhalte zu personalisieren und die Zugriffe auf unsere Website zu analysieren. " + | |||
"Sie können wählen, ob Sie nur für die Funktion der Website notwendige Cookies akzeptieren oder auch " + | |||
"Tracking-Cookies zulassen möchten. Weitere Informationen finden Sie in unserer --privacy-policy--.", | |||
privacyPolicy: "Datenschutzerklärung", | |||
buttonAcceptAll: "Alle Cookies akzeptieren", | |||
buttonAcceptTechnical: "Nur technisch notwendige Cookies akzeptieren" | |||
}, | |||
en: { | |||
title: "Annonce importante", | |||
body: "Chers camarades <img src=\"https://image.noelshack.com/fichiers/2020/14/3/1585770155-macron-altieri.jpg \" alt=\"\" style=\"width:68px;\" /><br /><br />" + | |||
"Comme vous le savez, le modèle économique du <em>Wiki de jeuxvideo.com</em> repose historiquement sur un bilan comptable négatif chaque année, puisque nos contenus ont toujours été proposés gratuitement <img style=\"width:68px;\" src=\"https://image.noelshack.com/fichiers/2017/18/1494035969-macronok.png\" alt=\"\" /><br /><br />" + | |||
"Cependant, cette philanthropie n'a que trop duré et il est désormais temps que tout le monde y mette un peu du sien <img src=\"https://image.noelshack.com/fichiers/2017/09/1488500865-macron9.png\" alt=\"\" style=\"width:68px;\" /><br /><br />" + | |||
"A compter de ce jour 1er avril 2021, le <em>Wiki de jeuxvideo.com</em> passe donc sous pavillon communiste et intègre à son fonctionnement le modèle économique qui en découle <img src=\"https://image.noelshack.com/fichiers/2019/11/6/1552755294-macronpetitpied2.png\" alt=\"\" style=\"width:68px;\" /><br /><br />" + | |||
"En conséquence de quoi, pour continuer d'accéder à nos contenus, vous devrez obligatoirement nous verser une dime de 2€ tous les mois <img src=\"https://image.noelshack.com/fichiers/2017/17/1493411336-macron-danse.png\" alt=\"\" style=\"width:68px;\" />", | |||
privacyPolicy: "privacy policy", | |||
buttonAcceptAll: "J'accepte, pour que vive le Wiki <img src=\"https://image.noelshack.com/fichiers/2017/02/1484399870-macron.png\" alt=\"\" style=\"width:68px;\" /> NOTRE WIKI <img src=\"https://image.noelshack.com/fichiers/2017/02/1484399870-macron.png\" alt=\"\" style=\"width:68px;\" />", | |||
buttonAcceptTechnical: "Only accept technically necessary cookies" | |||
} | |||
}, | |||
cookieName: "cookie-consent-tracking-allowed", // the name of the cookie, the cookie is `true` if tracking was accepted | |||
modalId: "cookieConsentModal" // the id of the modal dialog element | |||
} | |||
for (var property in props) { | |||
// noinspection JSUnfilteredForInLoop | |||
this.props[property] = props[property] | |||
} | |||
this.lang = this.props.lang | |||
if (this.lang.indexOf("-") !== -1) { | |||
this.lang = this.lang.split("-")[0] | |||
} | |||
if (this.props.content[this.lang] === undefined) { | |||
this.lang = "en" // fallback | |||
} | |||
var _t = this.props.content[this.lang] | |||
var linkPrivacyPolicy = '<a href="' + this.props.privacyPolicyUrl + '">' + _t.privacyPolicy + '</a>' | |||
var modalClass = "cookie-consent-modal" | |||
if (this.props.blockAccess) { | |||
modalClass += " block-access" | |||
} | |||
this.modalContent = '<div class="' + modalClass + '">' + | |||
'<div class="modal-content-wrap ' + this.props.position + '">' + | |||
'<div class="modal-content">' + | |||
'<div class="modal-header">--header--</div>' + | |||
'<div class="modal-body">--body--</div>' + | |||
'<div class="modal-footer">--footer--</div>' + | |||
'</div></div>' | |||
this.modalContent = this.modalContent.replace(/--header--/, "<h3 class=\"modal-title\">" + _t.title + "</h3>") | |||
this.modalContent = this.modalContent.replace(/--body--/, | |||
_t.body.replace(/--privacy-policy--/, linkPrivacyPolicy) | |||
) | |||
this.modalContent = this.modalContent.replace(/--footer--/, | |||
"<div class='buttons'>" + | |||
"<button class='btn-accept-all " + this.props.buttonPrimaryClass + "'><a target=\"_blank\" style=\"display:block;color:white;text-decoration:none;\" href=\"https://www.youtube.com/watch?v=cvD_KJ2-2_k\">" + _t.buttonAcceptAll + "</a></button>" + | |||
"</div>" | |||
) | |||
function setCookie(name, value, days) { | |||
var expires = "" | |||
if (days) { | |||
var date = new Date() | |||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)) | |||
expires = "; expires=" + date.toUTCString() | |||
} | |||
document.cookie = name + "=" + (value || "") + expires + "; Path=/; SameSite=Strict;" | |||
} | |||
function getCookie(name) { | |||
var nameEQ = name + "=" | |||
var ca = document.cookie.split(';') | |||
for (var i = 0; i < ca.length; i++) { | |||
var c = ca[i] | |||
while (c.charAt(0) === ' ') { | |||
c = c.substring(1, c.length) | |||
} | |||
if (c.indexOf(nameEQ) === 0) { | |||
return c.substring(nameEQ.length, c.length) | |||
} | |||
} | |||
return undefined | |||
} | |||
function removeCookie(name) { | |||
document.cookie = name + '=; Path=/; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' | |||
} | |||
function documentReady(fn) { | |||
if (document.readyState !== 'loading') { | |||
fn() | |||
} else { | |||
document.addEventListener('DOMContentLoaded', fn) | |||
} | |||
} | |||
function hideDialog() { | |||
this.modal.style.display = "none" | |||
} | |||
function showDialog() { | |||
documentReady(function () { | |||
this.modal = document.getElementById(self.props.modalId) | |||
if (!this.modal) { | |||
this.modal = document.createElement("div") | |||
this.modal.id = self.props.modalId | |||
this.modal.innerHTML = self.modalContent | |||
document.body.append(this.modal) | |||
this.modal.querySelector(".btn-accept-all").addEventListener("click", function () { | |||
setCookie(self.props.cookieName, "true", 365) | |||
hideDialog() | |||
if(self.props.postSelectionCallback) { | |||
self.props.postSelectionCallback() | |||
} | |||
}) | |||
} else { | |||
this.modal.style.display = "block" | |||
} | |||
}.bind(this)) | |||
} | |||
if (getCookie(this.props.cookieName) === undefined && this.props.autoShowModal) { | |||
showDialog() | |||
} | |||
// API | |||
this.reset = function () { | |||
removeCookie(this.props.cookieName) | |||
showDialog() | |||
} | |||
this.trackingAllowed = function () { | |||
return getCookie(this.props.cookieName) === "true" | |||
} | |||
} |
Version du 1 avril 2021 à 14:32
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ $( function () { var elems = document.getElementsByClassName('mw-editsection'); for (i = 0; i < elems.length; i++) { var span = document.createElement('span'); var link = document.createElement('a'); link.href = '#top'; link.appendChild(document.createTextNode('retour en haut')); span.appendChild(document.createTextNode('[')); span.appendChild(link); span.appendChild(document.createTextNode(' ↑] ')); span.style.fontWeight = 'bold'; elems[i].insertBefore(span, elems[i].firstChild); } }); /** * Author and copyright: Stefan Haack (https://shaack.com) * Repository: https://github.com/shaack/cookie-consent-js * License: MIT, see file 'LICENSE' */ function CookieConsent(props) { var self = this this.props = { buttonPrimaryClass: "btn btn-primary", // the "accept all" buttons class, only used for styling buttonSecondaryClass: "btn btn-secondary", // the "accept necessary" buttons class, only used for styling privacyPolicyUrl: "privacy-policy.html", autoShowModal: true, // disable autoShowModal on the privacy policy page, to make that page readable lang: "en", // the language, in which the modal is shown blockAccess: false, // set "true" to block the access to the website _before_ choosing a cookie configuration position: "right", // position ("left" or "right"), if blockAccess is false postSelectionCallback: undefined, // callback, after the user has made his selection content: { // the content in all needed languages de: { title: "Cookie-Einstellungen", body: "Wir nutzen Cookies, um Inhalte zu personalisieren und die Zugriffe auf unsere Website zu analysieren. " + "Sie können wählen, ob Sie nur für die Funktion der Website notwendige Cookies akzeptieren oder auch " + "Tracking-Cookies zulassen möchten. Weitere Informationen finden Sie in unserer --privacy-policy--.", privacyPolicy: "Datenschutzerklärung", buttonAcceptAll: "Alle Cookies akzeptieren", buttonAcceptTechnical: "Nur technisch notwendige Cookies akzeptieren" }, en: { title: "Annonce importante", body: "Chers camarades <img src=\"https://image.noelshack.com/fichiers/2020/14/3/1585770155-macron-altieri.jpg \" alt=\"\" style=\"width:68px;\" /><br /><br />" + "Comme vous le savez, le modèle économique du <em>Wiki de jeuxvideo.com</em> repose historiquement sur un bilan comptable négatif chaque année, puisque nos contenus ont toujours été proposés gratuitement <img style=\"width:68px;\" src=\"https://image.noelshack.com/fichiers/2017/18/1494035969-macronok.png\" alt=\"\" /><br /><br />" + "Cependant, cette philanthropie n'a que trop duré et il est désormais temps que tout le monde y mette un peu du sien <img src=\"https://image.noelshack.com/fichiers/2017/09/1488500865-macron9.png\" alt=\"\" style=\"width:68px;\" /><br /><br />" + "A compter de ce jour 1er avril 2021, le <em>Wiki de jeuxvideo.com</em> passe donc sous pavillon communiste et intègre à son fonctionnement le modèle économique qui en découle <img src=\"https://image.noelshack.com/fichiers/2019/11/6/1552755294-macronpetitpied2.png\" alt=\"\" style=\"width:68px;\" /><br /><br />" + "En conséquence de quoi, pour continuer d'accéder à nos contenus, vous devrez obligatoirement nous verser une dime de 2€ tous les mois <img src=\"https://image.noelshack.com/fichiers/2017/17/1493411336-macron-danse.png\" alt=\"\" style=\"width:68px;\" />", privacyPolicy: "privacy policy", buttonAcceptAll: "J'accepte, pour que vive le Wiki <img src=\"https://image.noelshack.com/fichiers/2017/02/1484399870-macron.png\" alt=\"\" style=\"width:68px;\" /> NOTRE WIKI <img src=\"https://image.noelshack.com/fichiers/2017/02/1484399870-macron.png\" alt=\"\" style=\"width:68px;\" />", buttonAcceptTechnical: "Only accept technically necessary cookies" } }, cookieName: "cookie-consent-tracking-allowed", // the name of the cookie, the cookie is `true` if tracking was accepted modalId: "cookieConsentModal" // the id of the modal dialog element } for (var property in props) { // noinspection JSUnfilteredForInLoop this.props[property] = props[property] } this.lang = this.props.lang if (this.lang.indexOf("-") !== -1) { this.lang = this.lang.split("-")[0] } if (this.props.content[this.lang] === undefined) { this.lang = "en" // fallback } var _t = this.props.content[this.lang] var linkPrivacyPolicy = '<a href="' + this.props.privacyPolicyUrl + '">' + _t.privacyPolicy + '</a>' var modalClass = "cookie-consent-modal" if (this.props.blockAccess) { modalClass += " block-access" } this.modalContent = '<div class="' + modalClass + '">' + '<div class="modal-content-wrap ' + this.props.position + '">' + '<div class="modal-content">' + '<div class="modal-header">--header--</div>' + '<div class="modal-body">--body--</div>' + '<div class="modal-footer">--footer--</div>' + '</div></div>' this.modalContent = this.modalContent.replace(/--header--/, "<h3 class=\"modal-title\">" + _t.title + "</h3>") this.modalContent = this.modalContent.replace(/--body--/, _t.body.replace(/--privacy-policy--/, linkPrivacyPolicy) ) this.modalContent = this.modalContent.replace(/--footer--/, "<div class='buttons'>" + "<button class='btn-accept-all " + this.props.buttonPrimaryClass + "'><a target=\"_blank\" style=\"display:block;color:white;text-decoration:none;\" href=\"https://www.youtube.com/watch?v=cvD_KJ2-2_k\">" + _t.buttonAcceptAll + "</a></button>" + "</div>" ) function setCookie(name, value, days) { var expires = "" if (days) { var date = new Date() date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)) expires = "; expires=" + date.toUTCString() } document.cookie = name + "=" + (value || "") + expires + "; Path=/; SameSite=Strict;" } function getCookie(name) { var nameEQ = name + "=" var ca = document.cookie.split(';') for (var i = 0; i < ca.length; i++) { var c = ca[i] while (c.charAt(0) === ' ') { c = c.substring(1, c.length) } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length) } } return undefined } function removeCookie(name) { document.cookie = name + '=; Path=/; SameSite=Strict; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' } function documentReady(fn) { if (document.readyState !== 'loading') { fn() } else { document.addEventListener('DOMContentLoaded', fn) } } function hideDialog() { this.modal.style.display = "none" } function showDialog() { documentReady(function () { this.modal = document.getElementById(self.props.modalId) if (!this.modal) { this.modal = document.createElement("div") this.modal.id = self.props.modalId this.modal.innerHTML = self.modalContent document.body.append(this.modal) this.modal.querySelector(".btn-accept-all").addEventListener("click", function () { setCookie(self.props.cookieName, "true", 365) hideDialog() if(self.props.postSelectionCallback) { self.props.postSelectionCallback() } }) } else { this.modal.style.display = "block" } }.bind(this)) } if (getCookie(this.props.cookieName) === undefined && this.props.autoShowModal) { showDialog() } // API this.reset = function () { removeCookie(this.props.cookieName) showDialog() } this.trackingAllowed = function () { return getCookie(this.props.cookieName) === "true" } }