PageSourceSearch

https://www.anchoreyes.com/wdf-common/age-gate-bypass/agegatebypass.js

js anchoreyes.com collected 2026-09-26 01:58:11 UTC 12,968 bytes, 413 lines download raw bytes

1if (typeof console === "undefined" || typeof console.log === "undefined") {
2  console = {};
3  console.log = function () { };
4}
5
6var lang = document.documentElement.lang;
7var globalConfig;
8var AgeGateByPass;
9if (!AgeGateByPass) {
10  AgeGateByPass = new Object();
11  AgeGateByPass.isToBypass = false;
12}
13var REQUIRED_BYPASS_PARAMS = ['utm_source', 'utm_medium'];
14
15var sanitizer = function (str) {
16  return str.replace(/[^\w.^-]/gi, function (c) {
17    return '&#' + c.charCodeAt(0) + ';';
18  });
19};
20
21const globalDomain = document.getElementById('ageGateBypass').getAttribute('data-domain-path');
22const reqUrl = window.location.search;
23const urlParams = new URLSearchParams(reqUrl);
24var hostName = window.location.hostname;
25var protocol = window.location.protocol;
26var env =
27  window.location.toString().indexOf("/dev/") > -1
28    ? "/dev"
29    : window.location.toString().indexOf("/stg/") > -1
30      ? "/stg"
31      : "";
32//env = "";
33var configUrl = protocol + "//" + hostName + env + "/wdf-common/age-gate-bypass/" + sanitizer(globalDomain) + "/campaigns.json";
34
35// if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
36//   configUrl = "./campaigns.json";
37// }
38
39// Set a Cookie
40function setCookieBypass(cName, cValue, expDays) {
41  let date = new Date();
42  date.setTime(date.getTime() + expDays * 24 * 60 * 60 * 1000);
43  const expires = 0;
44  if (expDays != 0) {
45    expires = "expires=" + date.toUTCString();
46  }
47  document.cookie = cName + "=" + cValue + "; " + expires + "; path=/";
48}
49
50function setLocalStorage(cName, cValue) {
51  localStorage.setItem(cName, JSON.stringify(cValue));
52}
53
54function setSessionStorage(cName, cValue) {
55  sessionStorage.setItem(cName, JSON.stringify(cValue));
56}
57
58function getCookieBypass(cName) {
59  const name = cName + "=";
60  const cDecoded = decodeURIComponent(document.cookie); //to be careful
61  const cArr = cDecoded.split("; ");
62  let res;
63  cArr.forEach((val) => {
64    if (val.indexOf(name) === 0) res = val.substring(name.length);
65  });
66  return res;
67}
68
69function bypass(config) {
70  const addCSS = (css) => (document.head.appendChild(document.createElement("style")).innerHTML = css);
71  if (config.elementsToHide) {
72    addCSS(`${config.elementsToHide}{ display:none!important;}`);
73
74    if(config.elementsToHide == '.sn_age_gate'){ //BB
75      document.querySelector('body').classList.remove("overflow-hidden");
76      document.querySelector('.sn_site_wrapper').classList.remove("_blur");
77    }
78  }
79
80  if (typeof (config.agegateCookieValue) == 'string') {
81    if ((config.agegateCookieValue).startsWith('#UTIL:')) {
82      let util = (config.agegateCookieValue).replace('#UTIL:', '');
83
84      switch (util) {
85        case 'TIMESTAMP':
86          config.agegateCookieValue = Date.now();
87          setLocalStorage(config.agegateCookieName, config.agegateCookieValue);
88          break;
89        default:
90          break;
91      }
92    }
93  }
94
95  setLocalStorage(config.agegateCookieName, config.agegateCookieValue);
96  setSessionStorage(config.agegateCookieName, config.agegateCookieValue);
97  setCookieBypass(config.agegateCookieName, config.agegateCookieValue, 0);
98  document.body.classList.remove('overflowHidden');
99  document.body.classList.remove('notScrollable');
100
101  window.dispatchEvent(new CustomEvent('sn:gtma:age-gate-bypass:ok'));
102
103  window.dispatchEvent(new CustomEvent('sn:gtma:age-gate:init_bypass'));
104
105  window.dispatchEvent(new CustomEvent('sn:gtma:age-gate:ok_bypass'));
106
107  if (config.refreshPage) {
108    location.reload();
109  }
110}
111
112function hideDivAgeGate(config) {
113  const addCSS = (css) => (document.head.appendChild(document.createElement("style")).innerHTML = css);
114  if (config.elementsToHide) {
115    addCSS(`${config.elementsToHide}{ display:none!important;}`);
116
117    if(config.elementsToHide == '.sn_age_gate'){ //BB
118      document.querySelector('body').classList.remove("overflow-hidden");
119      document.querySelector('.sn_site_wrapper').classList.remove("_blur");
120    }
121  }
122}
123
124function getConfig(configUrl) {
125  return fetch(configUrl).then((response) => response.json());
126}
127
128function manageDisappearingBypassDiv_old(bypassCloseElementId) {
129  let bypassCloseElement = document.getElementById(bypassCloseElementId);
130  if (bypassCloseElement) {
131    bypassCloseElement.click();
132  }
133}
134
135function manageDisappearingBypassDiv(div) {
136  if (div) {
137    div.click();
138  }
139}
140
141function verifyReOpenMessageDiv(config) {
142  reopenDivConf = config.reopenMessageDiv;
143  let cookie = getCookieBypass("ageGateBypassMessage");
144  if (cookie && cookie === "closed") {
145    let div = document.getElementById(reopenDivConf.id);
146
147    if (div !== null) {
148      div.remove();
149    }
150    div = document.createElement("div");
151
152
153    if (reopenDivConf.style && reopenDivConf.style.length > 0) {
154      div.style = reopenDivConf.style;
155    }
156    div.class = reopenDivConf.class;
157    div.id = reopenDivConf.id;
158
159    let p = document.createElement("p");
160    p.style = "margin:0;padding:0";
161    p.innerHTML = config.translations[lang] ? config.translations[lang].reopenMessageDivText : reopenDivConf.text;
162
163    // span that close the div
164    let span = document.createElement("span");
165    span.id = reopenDivConf.closeSpanId;
166    if (reopenDivConf.closeSpanStyle && reopenDivConf.closeSpanStyle.length > 0) {
167      span.style = reopenDivConf.closeSpanStyle;
168    }
169    span.innerHTML = config.translations[lang]
170      ? config.translations[lang].reopenMessageCloseText
171      : reopenDivConf.closeSpanText;
172    span.onclick = () => openMessageDiv(div, config);
173    p.appendChild(span);
174    div.appendChild(p);
175
176    if (reopenDivConf.containerClass && reopenDivConf.containerClass != '' && typeof (reopenDivConf.containerClass) != 'undefined') {
177      document.querySelector(reopenDivConf.containerClass).appendChild(div);
178    } else {
179      document.body.appendChild(div);
180    }
181  }
182}
183
184function openMessageDiv(div, config) {
185  div.style = "display: none";
186
187  let messageDiv = document.getElementById(config.bypassedDiv.id);
188  if (messageDiv) {
189    messageDiv.style = config.bypassedDiv.style;
190  } else createMessageDiv(config, true);
191}
192
193function verifyIsToCreateMessageDiv(config) {
194  bypassDivConfig = config.bypassedDiv;
195  let cookie = getCookieBypass("ageGateBypassMessage");
196  let div = document.getElementById(bypassDivConfig.id);
197  if (cookie === "created" && !div) {
198    createMessageDiv(config, true);
199  }
200}
201
202function createMessageDiv(config, forceRecreate) {
203  bypassDivConfig = config.bypassedDiv;
204  let cookie = getCookieBypass("ageGateBypassMessage");
205  if (!cookie || forceRecreate) {
206    if (cookie !== "created") {
207      setCookieBypass("ageGateBypassMessage", "created", 0);
208    }
209
210    let div = document.createElement("div");
211    if (bypassDivConfig.style && bypassDivConfig.style.length > 0) {
212      div.style = bypassDivConfig.style;
213    }
214    div.class = bypassDivConfig.class;
215    div.id = bypassDivConfig.id;
216
217    let p = document.createElement("p");
218    p.style = "margin:0;padding:0;margin:0 auto;max-width: calc(100% - 5px);font-size: 0.8rem;";
219    p.innerHTML = config.translations[lang] ? config.translations[lang].bypassedDivText : bypassDivConfig.text;
220    // span that close the div
221    let span = document.createElement("span");
222    span.id = bypassDivConfig.closeSpanId;
223    if (bypassDivConfig.closeSpanStyle && bypassDivConfig.closeSpanStyle.length > 0) {
224      span.style = bypassDivConfig.closeSpanStyle;
225    }
226    span.innerHTML = config.translations[lang]
227      ? config.translations[lang].bypassedCloseTest
228      : bypassDivConfig.closeSpanText;
229    div.onclick = () => closeMessageDiv(div, config);
230    p.appendChild(span);
231    div.appendChild(p);
232
233    if (bypassDivConfig.containerClass && bypassDivConfig.containerClass != '' && typeof (bypassDivConfig.containerClass) != 'undefined') {
234      document.querySelector(bypassDivConfig.containerClass).appendChild(div);
235    } else {
236      document.body.appendChild(div);
237    }
238    setTimeout(() => manageDisappearingBypassDiv(div), bypassDivConfig.disappearingSecs * 1000);
239  }
240}
241
242function closeMessageDiv(div, config) {
243  div.style = "display: none";
244  setCookieBypass("ageGateBypassMessage", "closed", 0);
245  verifyReOpenMessageDiv(config);
246}
247
248function checkResponse(res) {
249  if (res.status == "fulfilled") {
250    if (typeof (res) == "string") {
251      res = JSON.parse(res);
252    }
253    return res.value;
254  } else if (res.status == "rejected") {
255    return null;
256  }
257}
258
259function getCommonCampaigns(callback) {
260  var commonCampaignsUrl = protocol + "//" + hostName + env + "/wdf-common/age-gate-bypass/commoncampaigns.json";
261  let commonCampaigns = getConfig(commonCampaignsUrl);
262  let commonCampaignsObj = {};
263
264  Promise.allSettled([commonCampaigns])
265    .then(function (res) {
266      let [commonCampaigns] = res;
267
268      commonCampaigns = checkResponse(commonCampaigns);
269
270      if (commonCampaigns != null) {
271        commonCampaignsObj = commonCampaigns;
272      }
273
274      callback(commonCampaignsObj);
275    });
276}
277
278function mergeCampaigns(commonCampaigns, websiteCampaigns) {
279  for (let k in commonCampaigns) {
280    if (typeof (websiteCampaigns[k]) == 'undefined') {
281      websiteCampaigns[k] = commonCampaigns[k];
282    } else {
283      for (let j in commonCampaigns[k]) {
284        if (typeof (websiteCampaigns[k][j]) == 'undefined') {
285          websiteCampaigns[k][j] = commonCampaigns[k][j];
286        }
287      }
288    }
289  }
290
291  return websiteCampaigns;
292}
293
294function evaluateBypassParams(campaigns) {
295  let result = true;
296
297  for (let k in campaigns) {
298    let paramValue = urlParams.get(k);
299    let isRequired = REQUIRED_BYPASS_PARAMS.includes(k);
300
301    if (paramValue) {
302      if (!campaigns[k].hasOwnProperty(paramValue)) {
303        result = false;
304        break;
305      }
306    } else {
307        if (isRequired) {
308        result = false;
309        break;
310      }
311    }
312  }
313
314  return result;
315}
316
317function bypassGeo(callback) {
318  let countryPath = "https://df-controltower.mycampari.com/pp/wp-json/api/v1/geolocation";
319  let countryData = getConfig(countryPath);
320  let countryDataObj = {
321    'result' : false,
322    'data' : [],
323    'message' : '' 
324  };
325
326  Promise.allSettled([countryData])
327    .then(function (res) {
328      let [countryData] = res;
329
330      countryData = checkResponse(countryData);
331
332      if (countryData != null) {
333        countryDataObj = countryData;
334      }
335
336      callback(countryDataObj);
337    });
338}
339
340bypassGeo(function(geolocationObj){
341  if(geolocationObj['result']){
342    let forbiddenCountry = ['FR'];
343
344    if(forbiddenCountry.includes(geolocationObj['data'])){
345      return;
346    }
347  }
348
349  getConfig(configUrl)
350  .then((data) => {
351    globalConfig = data;
352
353    getCommonCampaigns(function (commonCampaigns) {
354      data.campaigns = mergeCampaigns(commonCampaigns, data.campaigns);
355      verifyReOpenMessageDiv(globalConfig);
356      verifyIsToCreateMessageDiv(globalConfig);
357
358      if (getCookieBypass(globalConfig.agegateCookieName)) {
359        AgeGateByPass.isToBypass = true;
360
361        //start: fix problem with glengrant custom agegate
362        setSessionStorage(globalConfig.agegateCookieName, globalConfig.agegateCookieValue);
363        //end: fix problem with glengrant custom agegate
364
365        let campaigns = data.campaigns;
366        let result = evaluateBypassParams(campaigns);
367
368        hideDivAgeGate(globalConfig);
369
370        if (result) {
371          AgeGateByPass.comboCountryId = globalConfig.comboCountryId;
372          createMessageDiv(globalConfig);
373        }
374      } else {
375        if (globalConfig.isBypassActive) {
376          let campaigns = data.campaigns;
377          let result = evaluateBypassParams(campaigns);
378
379          if (result) {
380            AgeGateByPass.isToBypass = true;
381            bypass(globalConfig);
382            AgeGateByPass.comboCountryId = globalConfig.comboCountryId;
383          }
384          if (AgeGateByPass.isToBypass) {
385            createMessageDiv(globalConfig);
386          }
387
388          console.log("AgeGateBypass exit with ", AgeGateByPass.isToBypass);
389        }
390      }
391      return null;
392    });
393  }).catch((error) => {
394    console.log("Error while fetching file : ", error);
395  });
396});
397
398// This function is used to handle the behavior of the reopen-message 
399// that covers the checkout button when the reservebar cart is opened.
400function toggleFooterBannerBasedOnModalCart() {
401  const modalOpen = document.getElementsByClassName("reservebar-cart active").length > 0;
402  const banner = document.getElementById("reopen-message");
403
404  if (!banner) return; 
405
406  if (modalOpen) {
407    banner.style.display = "none"; 
408  } else {
409    banner.style.display = ""; 
410  }
411}
412
413setInterval(toggleFooterBannerBasedOnModalCart, 500);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.