PageSourceSearch

https://lawnswood.com.au/wp-content/plugins/custom-popup-scheduler/js/modal.js

js lawnswood.com.au collected 2026-10-08 05:33:29 UTC 5,308 bytes, 121 lines download raw bytes

1(function () {
2    document.addEventListener('DOMContentLoaded', function () {
3        function shouldShowPopup() {
4            try {
5                const currentPath = window.location.pathname;
6                //console.log('Current Path:', currentPath);  // Debugging: Log the current path
7                const urls = cps_data.urls ? cps_data.urls.split(',').map(url => url.trim()).filter(url => url) : [];
8
9                let matchFound = false;
10                urls.forEach(url => {
11                    //console.log('Checking URL:', url);  // Debugging: Log each URL being checked
12                    if (url === 'all' || url === currentPath) {
13                        matchFound = true;
14                    } else if (url.startsWith('regex:')) {
15                        try {
16                            const regexPattern = new RegExp(url.slice(6), 'i');
17                            if (regexPattern.test(currentPath)) {
18                                matchFound = true;
19                            }
20                        } catch (e) {
21                            console.error('Invalid regex pattern:', url, e);
22                        }
23                    }
24                });
25
26                if (!matchFound) {
27                    return false;
28                }
29
30                const override = cps_data.override;
31                if (override === 'on') return true;
32                if (override === 'off') return false;
33
34                const schedule = cps_data.schedule;
35                const currentDate = new Date();
36                const options = { timeZone: cps_data.timezone, weekday: 'long', hour: '2-digit', minute: '2-digit', hour12: false };
37                const formatter = new Intl.DateTimeFormat('en-US', options);
38                const parts = formatter.formatToParts(currentDate);
39                const currentDay = parts.find(p => p.type === 'weekday').value.toLowerCase();
40                const currentTime = parts.find(p => p.type === 'hour').value + ':' + parts.find(p => p.type === 'minute').value;
41
42                if (schedule[currentDay]) {
43                    const timeRanges = schedule[currentDay].split(',');
44                    for (let range of timeRanges) {
45                        const [start, end] = range.trim().split('-');
46                        if (currentTime >= start && currentTime <= end) {
47                            return true;
48                        }
49                    }
50                }
51            } catch (e) {
52                console.error('Error determining whether to show popup:', e);
53            }
54            return false;
55        }
56
57        function setCookie(name, value, hours) {
58            try {
59                const date = new Date();
60                date.setTime(date.getTime() + (hours * 60 * 60 * 1000)); // Convert hours to milliseconds
61                const expires = "expires=" + date.toUTCString();
62                document.cookie = name + "=" + value + ";" + expires + ";path=/";
63            } catch (e) {
64                console.error('Error setting cookie:', e);
65            }
66        }
67
68        function getCookie(name) {
69            try {
70                const nameEQ = name + "=";
71                const cookies = document.cookie.split(';');
72                for (let i = 0; i < cookies.length; i++) {
73                    let cookie = cookies[i];
74                    while (cookie.charAt(0) === ' ') cookie = cookie.substring(1);
75                    if (cookie.indexOf(nameEQ) === 0) return cookie.substring(nameEQ.length, cookie.length);
76                }
77            } catch (e) {
78                console.error('Error getting cookie:', e);
79            }
80            return null;
81        }
82
83        //if(getCookie('popupDismissed')) {
84        //    console.log('popupDismissed cookie found');
85        //} else {
86        //    console.log('popupDismissed cookie not found');
87        //}
88
89        if (shouldShowPopup() && !getCookie('popupDismissed')) {
90            try {
91                const message = cps_data.message;
92                const dismissalPeriod = parseInt(cps_data.dismissalPeriod, 10) || 24; // Default to 24 hours if not set
93
94                // Create overlay
95                const overlay = document.createElement('div');
96                overlay.id = 'popup-overlay';
97                document.body.appendChild(overlay);
98
99                // Create modal
100                const modal = document.createElement('div');
101                modal.id = 'popup-modal';
102                modal.style.display = 'none';
103                modal.innerHTML = '<span id="close-popup">&times;</span>' + message;
104                document.body.appendChild(modal);
105
106                // Show overlay and modal
107                overlay.style.display = 'block';
108                modal.style.display = 'block';
109
110                // Add event listener to close the modal and overlay
111                document.getElementById('close-popup').addEventListener('click', function () {
112                    modal.style.display = 'none';
113                    overlay.style.display = 'none';
114                    setCookie('popupDismissed', 'true', dismissalPeriod); // Use configurable hours
115                });
116            } catch (e) {
117                console.error('Error displaying popup:', e);
118            }
119        }
120    });
121})();

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.