PageSourceSearch

https://www.istudymaths.com/wp-content/plugins/cookie-guard-minimal/assets/js/cgm.js?ver=1.0.0

js istudymaths.com collected 2026-10-02 01:32:50 UTC 5,393 bytes, 136 lines download raw bytes

1(function(){
2  function setCookie(name, value, days) {
3    var d = new Date();
4    d.setTime(d.getTime() + (days*24*60*60*1000));
5    var expires = "expires="+ d.toUTCString();
6    document.cookie = name + "=" + encodeURIComponent(value) + ";" + expires + ";path=/;SameSite=Lax";
7  }
8  function getCookie(name) {
9    var cname = name + "=";
10    var decodedCookie = decodeURIComponent(document.cookie || '');
11    var ca = decodedCookie.split(';');
12    for (var i=0;i<ca.length;i++){
13      var c = ca[i].trim();
14      if (c.indexOf(cname) === 0) return c.substring(cname.length, c.length);
15    }
16    return null;
17  }
18  function delCookie(name){
19    document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;";
20  }
21
22  function parseConsent(){
23    try { var v = getCookie('cgm_consent'); return v ? JSON.parse(v) : null; } catch(e){ return null; }
24  }
25
26  function buildBanner(opts){
27    var root = document.getElementById('cgm-root');
28    if(!root) return;
29    if(parseConsent()) return;
30
31    var positionClass = opts.position === 'top' ? 'cgm-top' : 'cgm-bottom';
32    root.innerHTML = ''
33      + '<div class="cgm-banner '+positionClass+'" role="dialog" aria-live="polite" aria-label="Cookie notice">'
34      + '  <div class="cgm-content">'
35      + '    <div class="cgm-text">'
36      + '      <strong class="cgm-title">'+ h(opts.title) +'</strong>'
37      + '      <span class="cgm-message">'+ h(opts.message) +' '
38      + (opts.learn_more_url ? '<a class="cgm-learn" href="'+ encodeURI(opts.learn_more_url) +'" target="_blank" rel="noopener">'+ h(opts.learn_more_text) +'</a>.' : '')
39      + '      </span>'
40      + '    </div>'
41      + '    <div class="cgm-actions">'
42      + '      <button class="cgm-btn cgm-btn-secondary" data-action="reject">'+ h(opts.reject_all_text) +'</button>'
43      + '      <button class="cgm-btn cgm-btn-primary" data-action="accept">'+ h(opts.accept_all_text) +'</button>'
44      + '    </div>'
45      + '  </div>'
46      + '</div>';
47    applyPalette(opts.palette);
48    bindBannerEvents(opts);
49  }
50
51  function bindBannerEvents(opts){
52    var root = document.getElementById('cgm-root');
53    if(!root) return;
54    root.addEventListener('click', function(e){
55      var t = e.target; if(!(t instanceof Element)) return;
56      var action = t.getAttribute('data-action'); if(!action) return;
57      if(action === 'accept'){
58        var cons = {necessary:true, preferences:true, analytics:true, marketing:true};
59        saveConsent(cons, opts.days); removeBanner(); runAllowedScripts(cons);
60      } else if(action === 'reject'){
61        var cons = {necessary:true, preferences:false, analytics:false, marketing:false};
62        saveConsent(cons, opts.days); removeBanner();
63      }
64    });
65  }
66
67  function removeBanner(){
68    var root = document.getElementById('cgm-root');
69    if(root){ root.innerHTML=''; }
70  }
71
72  function saveConsent(consent, days){
73    setCookie('cgm_consent', JSON.stringify(consent), days || 180);
74    if (typeof CGM !== 'undefined') {
75      var data = new FormData();
76      data.append('action', 'cgm_save_consent');
77      data.append('nonce', CGM.nonce);
78      data.append('consent', JSON.stringify(consent));
79      fetch(CGM.ajax_url, {method:'POST', body:data});
80    }
81    if (window.dispatchEvent) {
82      window.dispatchEvent(new CustomEvent('cgm:consentChanged', { detail: consent }));
83    }
84  }
85
86  function resetConsent(){
87    delCookie('cgm_consent');
88    var root = document.getElementById('cgm-root');
89    if(root && typeof CGM !== 'undefined'){ buildBanner(CGM.opts); }
90  }
91
92  function runAllowedScripts(consent){
93    if(!consent) return;
94    if(!(consent.analytics || consent.marketing || consent.preferences)) return;
95
96    var allowed = Object.keys(consent).filter(function(k){ return consent[k]; });
97    var candidates = document.querySelectorAll('script[type="text/plain"][data-cgm-category]');
98    candidates.forEach(function(s){
99      var cat = s.getAttribute('data-cgm-category');
100      if(allowed.indexOf(cat) === -1) return;
101      var newS = document.createElement('script');
102      Array.prototype.slice.call(s.attributes).forEach(function(attr){
103        if(attr.name === 'type') return;
104        if(attr.name === 'data-src'){
105          newS.setAttribute('src', attr.value);
106        } else if(attr.name.indexOf('data-') === 0 && attr.name !== 'data-cgm-category'){
107          newS.setAttribute(attr.name.replace(/^data-/, ''), attr.value);
108        }
109      });
110      if(s.text && s.text.trim().length){
111        newS.text = s.text;
112      }
113      s.parentNode.insertBefore(newS, s);
114      s.parentNode.removeChild(s);
115    });
116  }
117
118  function applyPalette(p){
119    var r = document.documentElement;
120    r.style.setProperty('--cgm-bg', p.bg || '#0f172a');
121    r.style.setProperty('--cgm-text', p.text || '#ffffff');
122    r.style.setProperty('--cgm-button', p.button || '#22c55e');
123  }
124  function h(s){ return String(s).replace(/[&<>"']/g, function(m){ return ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[m]; }); }
125
126  window.CGM = window.CGM || {};
127  window.CGM.resetConsent = resetConsent;
128
129  document.addEventListener('DOMContentLoaded', function(){
130    if (typeof CGM === 'undefined') return;
131    buildBanner(CGM.opts);
132    var cons = parseConsent();
133    if(cons){ runAllowedScripts(cons); }
134    window.addEventListener('cgm:consentChanged', function(ev){ runAllowedScripts(ev.detail || {}); });
135  });
136})();

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.