MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
(function () { | (function () { | ||
const KEY = " | const KEY = "alphax_entry_consent"; | ||
const ANALYTICS_KEY = "alphax_analytics_consent"; | |||
const MAX_AGE = 30 * 24 * 60 * 60 * 1000; | const MAX_AGE = 30 * 24 * 60 * 60 * 1000; | ||
const GA_ID = "G-XXXXXXXXXX"; | |||
const saved = localStorage.getItem(KEY); | const saved = localStorage.getItem(KEY); | ||
if (saved && (Date.now() - saved < MAX_AGE)) { | if (saved && (Date.now() - Number(saved) < MAX_AGE)) { | ||
const analyticsConsent = localStorage.getItem(ANALYTICS_KEY); | |||
if (analyticsConsent === "granted") { | |||
loadGoogleAnalytics(); | |||
} | |||
return; | return; | ||
} | } | ||
| Line 60: | Line 66: | ||
color:#e4e4ea; | color:#e4e4ea; | ||
cursor:pointer; | cursor:pointer; | ||
line-height:1.5; | |||
} | } | ||
#checks input{ | #checks input{ | ||
margin-right:10px; | margin-right:10px; | ||
} | |||
#optional-title{ | |||
margin-top:22px; | |||
margin-bottom:8px; | |||
font-size:13px; | |||
font-weight:700; | |||
letter-spacing:0.04em; | |||
text-transform:uppercase; | |||
color:#9ca3af; | |||
} | } | ||
| Line 146: | Line 163: | ||
<input type="checkbox" id="c3"> | <input type="checkbox" id="c3"> | ||
I agree to the Privacy Policy | I agree to the Privacy Policy | ||
</label> | |||
<div id="optional-title">Optional</div> | |||
<label> | |||
<input type="checkbox" id="c4"> | |||
Allow anonymous analytics to help improve the website | |||
</label> | </label> | ||
| Line 151: | Line 175: | ||
<div id="buttons"> | <div id="buttons"> | ||
<button id="enter">Enter</button> | <button id="enter">Enter</button> | ||
<button id="exit">Exit</button> | <button id="exit">Exit</button> | ||
</div> | </div> | ||
<div id="links"> | <div id="links"> | ||
<a href="/index.php?title=Terms_and_Conditions">T&C</a> | <a href="/index.php?title=Terms_and_Conditions">T&C</a> | ||
<a href="/index.php?title=Datenschutz">Privacy Policy</a> | <a href="/index.php?title=Datenschutz">Privacy Policy</a> | ||
</div> | </div> | ||
| Line 170: | Line 192: | ||
const c2 = document.getElementById("c2"); | const c2 = document.getElementById("c2"); | ||
const c3 = document.getElementById("c3"); | const c3 = document.getElementById("c3"); | ||
const c4 = document.getElementById("c4"); | |||
const enter = document.getElementById("enter"); | const enter = document.getElementById("enter"); | ||
function checkAll(){ | function checkAll(){ | ||
if(c1.checked && c2.checked && c3.checked){ | if (c1.checked && c2.checked && c3.checked) { | ||
enter.classList.add("active"); | enter.classList.add("active"); | ||
enter.disabled=false; | enter.disabled = false; | ||
}else{ | } else { | ||
enter.classList.remove("active"); | enter.classList.remove("active"); | ||
enter.disabled=true; | enter.disabled = true; | ||
} | |||
} | } | ||
c1.onchange = checkAll; | |||
c2.onchange = checkAll; | |||
c3.onchange = checkAll; | |||
enter.disabled = true; | |||
function loadGoogleAnalytics() { | |||
if (window.__gaLoaded) return; | |||
window.__gaLoaded = true; | |||
window.dataLayer = window.dataLayer || []; | |||
function gtag() { | |||
dataLayer.push(arguments); | |||
} | |||
window.gtag = gtag; | |||
gtag("consent", "default", { | |||
analytics_storage: "granted" | |||
}); | |||
const script = document.createElement("script"); | |||
script.async = true; | |||
script.src = "https://www.googletagmanager.com/gtag/js?id=" + encodeURIComponent(GA_ID); | |||
document.head.appendChild(script); | |||
gtag("js", new Date()); | |||
gtag("config", GA_ID, { | |||
anonymize_ip: true | |||
}); | |||
} | } | ||
enter.onclick = function(){ | |||
localStorage.setItem(KEY, String(Date.now())); | |||
if (c4.checked) { | |||
localStorage.setItem(ANALYTICS_KEY, "granted"); | |||
loadGoogleAnalytics(); | |||
} else { | |||
localStorage.setItem(ANALYTICS_KEY, "denied"); | |||
} | |||
overlay.remove(); | |||
overlay.remove(); | |||
}; | }; | ||
document.getElementById("exit").onclick=function(){ | document.getElementById("exit").onclick = function(){ | ||
window.location.href="https://google.com"; | window.location.href = "https://google.com"; | ||
}; | }; | ||
})(); | })(); | ||
Revision as of 00:27, 16 March 2026
(function () {
const KEY = "alphax_entry_consent";
const ANALYTICS_KEY = "alphax_analytics_consent";
const MAX_AGE = 30 * 24 * 60 * 60 * 1000;
const GA_ID = "G-XXXXXXXXXX";
const saved = localStorage.getItem(KEY);
if (saved && (Date.now() - Number(saved) < MAX_AGE)) {
const analyticsConsent = localStorage.getItem(ANALYTICS_KEY);
if (analyticsConsent === "granted") {
loadGoogleAnalytics();
}
return;
}
const style = document.createElement("style");
style.innerHTML = `
#age-overlay{
position:fixed;
inset:0;
background:rgba(0,0,0,0.85);
backdrop-filter:blur(8px);
display:flex;
align-items:center;
justify-content:center;
z-index:999999;
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial;
}
#age-box{
background:#0f0f12;
border:1px solid rgba(255,255,255,0.08);
border-radius:20px;
padding:40px 34px;
max-width:520px;
width:90%;
color:white;
box-shadow:0 25px 80px rgba(0,0,0,0.6);
text-align:center;
}
#age-box h2{
margin-top:0;
font-size:32px;
margin-bottom:18px;
}
#age-text{
color:#cfcfd6;
line-height:1.6;
margin-bottom:28px;
}
#checks{
text-align:left;
margin-bottom:28px;
}
#checks label{
display:block;
margin:12px 0;
font-size:15px;
color:#e4e4ea;
cursor:pointer;
line-height:1.5;
}
#checks input{
margin-right:10px;
}
#optional-title{
margin-top:22px;
margin-bottom:8px;
font-size:13px;
font-weight:700;
letter-spacing:0.04em;
text-transform:uppercase;
color:#9ca3af;
}
#buttons{
display:flex;
gap:14px;
justify-content:center;
margin-top:10px;
}
#enter{
background:#34d27a;
color:#05110b;
border:none;
padding:14px 26px;
border-radius:10px;
font-size:16px;
font-weight:700;
cursor:pointer;
opacity:0.4;
}
#enter.active{
opacity:1;
}
#exit{
background:#e74c3c;
border:none;
color:white;
padding:14px 22px;
border-radius:10px;
font-size:16px;
cursor:pointer;
}
#links{
margin-top:22px;
font-size:13px;
opacity:0.8;
}
#links a{
color:#bbb;
margin:0 10px;
text-decoration:none;
}
#links a:hover{
color:white;
}
`;
document.head.appendChild(style);
const overlay = document.createElement("div");
overlay.id = "age-overlay";
overlay.innerHTML = `
<div id="age-box">
<h2>18+ Access</h2>
<div id="age-text">
This website contains adult educational content.<br>
You must confirm the following to enter.
</div>
<div id="checks">
<label>
<input type="checkbox" id="c1">
I confirm that I am at least 18 years old
</label>
<label>
<input type="checkbox" id="c2">
I agree to the Terms & Conditions
</label>
<label>
<input type="checkbox" id="c3">
I agree to the Privacy Policy
</label>
<div id="optional-title">Optional</div>
<label>
<input type="checkbox" id="c4">
Allow anonymous analytics to help improve the website
</label>
</div>
<div id="buttons">
<button id="enter">Enter</button>
<button id="exit">Exit</button>
</div>
<div id="links">
<a href="/index.php?title=Terms_and_Conditions">T&C</a>
<a href="/index.php?title=Datenschutz">Privacy Policy</a>
</div>
</div>
`;
document.body.appendChild(overlay);
const c1 = document.getElementById("c1");
const c2 = document.getElementById("c2");
const c3 = document.getElementById("c3");
const c4 = document.getElementById("c4");
const enter = document.getElementById("enter");
function checkAll(){
if (c1.checked && c2.checked && c3.checked) {
enter.classList.add("active");
enter.disabled = false;
} else {
enter.classList.remove("active");
enter.disabled = true;
}
}
c1.onchange = checkAll;
c2.onchange = checkAll;
c3.onchange = checkAll;
enter.disabled = true;
function loadGoogleAnalytics() {
if (window.__gaLoaded) return;
window.__gaLoaded = true;
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
window.gtag = gtag;
gtag("consent", "default", {
analytics_storage: "granted"
});
const script = document.createElement("script");
script.async = true;
script.src = "https://www.googletagmanager.com/gtag/js?id=" + encodeURIComponent(GA_ID);
document.head.appendChild(script);
gtag("js", new Date());
gtag("config", GA_ID, {
anonymize_ip: true
});
}
enter.onclick = function(){
localStorage.setItem(KEY, String(Date.now()));
if (c4.checked) {
localStorage.setItem(ANALYTICS_KEY, "granted");
loadGoogleAnalytics();
} else {
localStorage.setItem(ANALYTICS_KEY, "denied");
}
overlay.remove();
};
document.getElementById("exit").onclick = function(){
window.location.href = "https://google.com";
};
})();