PageSourceSearch

https://goforthwilliamson.com/wp-content/plugins/fcg-cookie-consent/assets/fcg-cookie.js?ver=1.0.2

js goforthwilliamson.com collected 2026-10-06 02:47:23 UTC 6,772 bytes, 224 lines download raw bytes

1function fcgGenerateConsentId() {
2    if (window.crypto && crypto.randomUUID) {
3        return crypto.randomUUID();
4    }
5
6    return 'fcg-' + Date.now() + '-' + Math.random().toString(36).substring(2, 15);
7}
8
9function fcgGetConsentId() {
10    var consentId = fcgGetCookie('fcg_consent_id');
11
12    if (!consentId) {
13        consentId = fcgGenerateConsentId();
14        fcgSetCookie('fcg_consent_id', consentId, 365);
15    }
16
17    return consentId;
18}
19
20function fcgSetCookie(name, value, days) {
21    var d = new Date();
22    d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
23    document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + d.toUTCString() + "; path=/; SameSite=Lax";
24}
25
26function fcgGetCookie(name) {
27    var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
28    return match ? decodeURIComponent(match[2]) : null;
29}
30
31function fcgApplyConsent(c) {
32    if (typeof gtag === 'function') {
33        gtag('consent', 'update', {
34            analytics_storage: c.analytics ? 'granted' : 'denied',
35            ad_storage: c.marketing ? 'granted' : 'denied',
36            ad_user_data: c.marketing ? 'granted' : 'denied',
37            ad_personalization: c.marketing ? 'granted' : 'denied',
38            functionality_storage: c.functional ? 'granted' : 'denied',
39            security_storage: 'granted'
40        });
41    }
42}
43
44function fcgLogConsent(c, action, callback) {
45    var nonceField = document.getElementById('fcg_cookie_consent_nonce');
46    var nonce = nonceField ? nonceField.value : '';
47
48    var formData = new FormData();
49    formData.append('action', 'fcg_cookie_log_consent');
50    formData.append('nonce', nonce);
51    formData.append('consent_id', fcgGetConsentId());
52    formData.append('consent_action', action);
53    formData.append('consent', JSON.stringify(c));
54
55    fetch('/wp-admin/admin-ajax.php', {
56        method: 'POST',
57        credentials: 'same-origin',
58        body: formData
59    })
60    .then(function (response) {
61        return response.json();
62    })
63    .then(function (data) {
64        console.log('FCG consent log response:', data);
65        
66        if (typeof callback === 'function') {
67            callback();
68        }
69    })
70    .catch(function (error) {
71        console.error('FCG consent log error:', error);
72    });
73}
74
75function fcgSave(c, action) {
76
77    var banner = document.getElementById('fcg-cookie-banner');
78    var modal = document.getElementById('fcg-cookie-modal');
79
80    var version = banner ? banner.getAttribute('data-consent-version') : null;
81    c.version = version;
82
83    fcgSetCookie('fcg_cookie_consent', JSON.stringify(c), 180);
84    fcgApplyConsent(c);
85
86    if (banner) banner.style.display = 'none';
87    if (modal) modal.style.display = 'none';
88
89    if (c.analytics || c.marketing) {
90        fcgLogConsent(c, action, function () {
91            window.location.reload();
92        });
93    } else {
94        fcgLogConsent(c, action);
95    }
96}
97
98function fcgStopEvent(e) {
99    if (e) {
100        e.preventDefault();
101        e.stopPropagation();
102        e.stopImmediatePropagation();
103    }
104}
105
106function fcgAcceptAll(e) {
107    fcgStopEvent(e);
108    fcgSave({ necessary: true, analytics: true, marketing: true, functional: true }, 'accept_all');
109}
110
111function fcgRejectAll(e) {
112    fcgStopEvent(e);
113    fcgSave({ necessary: true, analytics: false, marketing: false, functional: false }, 'reject_all');
114}
115
116function fcgOpenPrefs(e) {
117    fcgStopEvent(e);
118
119    var saved = fcgGetCookie('fcg_cookie_consent');
120
121    if (saved) {
122        try {
123            var c = JSON.parse(saved);
124
125            document.getElementById('fcg-analytics').checked = !!c.analytics;
126            document.getElementById('fcg-marketing').checked = !!c.marketing;
127            document.getElementById('fcg-functional').checked = !!c.functional;
128
129        } catch (err) {}
130    }
131
132    var modal = document.getElementById('fcg-cookie-modal');
133    if (modal) modal.style.display = 'flex';
134}
135
136function fcgClosePrefs() {
137    var modal = document.getElementById('fcg-cookie-modal');
138    if (modal) modal.style.display = 'none';
139}
140
141function fcgSavePrefs() {
142    fcgSave({
143        necessary: true,
144        analytics: document.getElementById('fcg-analytics').checked,
145        marketing: document.getElementById('fcg-marketing').checked,
146        functional: document.getElementById('fcg-functional').checked
147    }, 'save_preferences');
148}
149
150document.addEventListener('DOMContentLoaded', function () {
151    var banner = document.getElementById('fcg-cookie-banner');
152    var currentVersion = banner ? banner.getAttribute('data-consent-version') : null;
153    var gpcEnabled = banner && banner.getAttribute('data-gpc-enabled') === '1';
154    var gpcDetected = navigator.globalPrivacyControl === true;
155    
156    var saved = fcgGetCookie('fcg_cookie_consent');
157    
158    if (saved) {
159        try {
160            var consent = JSON.parse(saved);
161    
162            if (consent.version === currentVersion) {
163
164                if (
165                    gpcEnabled &&
166                    gpcDetected &&
167                    (!consent.gpc || consent.marketing)
168                ) {
169                    consent.marketing = false;
170                    consent.gpc = true;
171                
172                    fcgSetCookie(
173                        'fcg_cookie_consent',
174                        JSON.stringify(consent),
175                        180
176                    );
177                
178                    fcgLogConsent(consent, 'gpc_signal');
179                }
180            
181                fcgApplyConsent(consent);
182                return;
183            }
184    
185            // Old consent version - delete it
186            document.cookie = "fcg_cookie_consent=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
187    
188        } catch (e) {
189            // Invalid cookie - remove it
190            document.cookie = "fcg_cookie_consent=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
191        }
192    }
193    
194    if (banner) banner.style.display = 'block';
195});
196
197
198
199
200
201function fcgHandleButtonEvent(e) {
202    var btn = e.target.closest('button');
203    if (!btn) return;
204
205    if (btn.closest('#fcg-cookie-banner')) {
206        e.preventDefault();
207        e.stopPropagation();
208
209        if (btn.classList.contains('fcg-btn-primary')) fcgAcceptAll(e);
210        if (btn.classList.contains('fcg-btn-secondary')) fcgRejectAll(e);
211        if (btn.classList.contains('fcg-btn-link')) fcgOpenPrefs(e);
212    }
213
214    if (btn.closest('#fcg-cookie-modal')) {
215        e.preventDefault();
216        e.stopPropagation();
217
218        if (btn.classList.contains('fcg-btn-primary')) fcgSavePrefs();
219        if (btn.classList.contains('fcg-btn-secondary')) fcgClosePrefs();
220    }
221}
222
223document.addEventListener('mousedown', fcgHandleButtonEvent, true);
224document.addEventListener('touchstart', fcgHandleButtonEvent, true);

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.