PageSourceSearch

https://angelmansyndromenews.com/wp-content/plugins/BioNews_Plugin/public/js/bionews-public.js?ver=1.9.44

js angelmansyndromenews.com collected 2026-10-02 20:07:28 UTC 14,757 bytes, 402 lines download raw bytes

1(function($) {
2    window.activeAds = [];
3    window.dataLayer = window.dataLayer || [];
4
5    var adElems;
6    var adParams;
7    var adSpecs;
8
9	/**
10	 * Uses the matomo bots list to check if user agent is a bot crawler
11	 */
12	/*
13	function checkForBot() {
14		
15		try {
16			if (typeof botsList === 'undefined')
17				return;
18			
19			var foundBot = botsList.find(function(el) {
20				var regex = new RegExp(`(?:^|[^A-Z0-9_-]|[^A-Z0-9-]_|sprd-|MZ-)(?:${el.regex})`, "i");
21				var userAgent = navigator.userAgent;
22				var matches = userAgent.match(regex);
23				if (matches) {
24					return true;
25				}
26			});
27
28			if (typeof foundBot !== 'undefined') {
29				bnAdSpec.isBot = true;
30				bnAdSpec.userAgentName = foundBot.name;
31			}
32		}
33		catch(e) {
34			console.log(e);
35		}
36
37	}
38	*/
39
40	/**
41	 * 
42	 * Checks if the user agent strings contains one of the blacklisted user agents entered in the WordPress admin
43	 */
44	function checkForBlacklistedUserAgent() {
45		if (typeof blacklistedUserAgents !== 'object' || typeof navigator === 'undefined' || !navigator.userAgent) {
46			return;
47		}
48
49		blacklistedUserAgents.some(function(el) {
50			if (navigator.userAgent.includes(el) && bnAdSpec) {
51				bnAdSpec.disableAds = true;
52				bnAdSpec.userAgentName = el;
53				var style = `
54						<style>
55							#bn-ads-blocked-notice {
56								position: fixed;
57								color: #fff;
58								padding: 1rem;
59								font-size: 0.75rem;
60								bottom: 2rem;
61								right: 2rem;
62								z-index: 1000;
63								background-color: rgba(1, 122, 218, 0.8);
64								max-width: 90%;
65								width: 300px;
66								cursor: pointer;
67							}
68						</style>`;
69				var notice = `
70					<div id="bn-ads-blocked-notice">
71						<p>
72							NOTICE: Ads blocked on user agent ${navigator.userAgent}
73						</p>
74					</div>`;
75
76				if ($('#wpadminbar').length > 0 ) {
77					$('body').append(style).append(notice);
78					$('#bn-ads-blocked-notice').on('click', function() {
79						$('#bn-ads-blocked-notice').fadeOut();
80					});
81				}
82
83				return true;
84			}
85		});
86	}
87
88	/**
89	 * Get the user agent name if it's not a bot
90	 */
91	function getUserAgentInfo() {
92		if (typeof UAParser === 'undefined')
93			return;
94		var uap = new UAParser();
95		var result = uap.getResult();
96		bnAdSpec.userAgentName = result.browser.name ?? navigator.userAgent;
97	}
98
99    var d = new Date();
100    d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
101    var expires = "; expires=" + d.toGMTString();
102
103    // get the values into the array and push to dataLayer
104    updateAdParams();
105
106    window.startAdScript = function() {
107        console.log('start ads');
108        adElems = document.getElementsByClassName('ads_container');
109        console.log('Found ' + adElems.length + ' ad containers');
110
111        var adBlocks = [];
112        let isMobile = window.matchMedia("only screen and (max-width: 760px)").matches;
113        var lazyEnable = $.bionews.getCookie('LAZY_LOAD');
114        if (adElems && adElems.length > 0) {
115            var lazyLoadConfig = {
116                fetchMarginPercent: 100,
117                renderMarginPercent: 20,
118                mobileScaling: 1.0,
119            };
120            window.googletag = window.googletag || {
121                cmd: []
122            };
123
124            googletag.cmd.push(function() {
125
126                googletag.pubads().disableInitialLoad();
127                googletag.pubads().setTargeting("ugc", "false");
128                if((adSpecs.lazyLoaded !== false && adSpecs.lazyLoadedDefer !== true) || (adSpecs.lazyLoaded !== false && lazyEnable != undefined) ) {
129                    console.log('lazyload enabled');
130                    googletag.pubads().enableLazyLoad(lazyLoadConfig);
131                }
132                if(adSpecs.singleRequest !== false) {
133                    googletag.pubads().enableSingleRequest();
134                }
135                googletag.pubads().collapseEmptyDivs();
136                googletag.pubads().enableAsyncRendering();
137
138                for (let [key, value] of Object.entries(adParams.pageLevelTargeting)) {
139                    googletag.pubads()
140                        .setTargeting(`${key}`, `${value}`);
141                }
142
143                googletag.enableServices();
144                for (var i = 0; i < adElems.length; i++) {
145                    var adSizesJson = [];
146                    var adSlotId = adElems[i].id;
147                    var adSize1 = adElems[i].getAttribute('data-ad-size1').split(',');
148                    var adSize2 = adElems[i].getAttribute('data-ad-size2');
149                    var adTarget = adElems[i].getAttribute('data-ad-target');
150                    var isMobileFlag = adElems[i].getAttribute('data-show-mobile');
151
152                    if(isMobile == true && isMobileFlag == 'true') {
153                        adSizesJson.push([parseInt(adSize1[0]), parseInt(adSize1[1])]);
154                        if (adSize2 !== null && adSize2 != "") {
155                            adSize2 = adSize2.split(',');
156                            adSizesJson.push([parseInt(adSize2[0]), parseInt(adSize2[1])]);
157                        }
158                        buildSlot(adElems[i], adSpecs, adSizesJson, adSlotId, adTarget);
159                    } else if(isMobile == false && isMobileFlag == 'false') {
160                        adSizesJson.push([parseInt(adSize1[0]), parseInt(adSize1[1])]);
161                        if (adSize2 !== null && adSize2 != "") {
162                            adSize2 = adSize2.split(',');
163                            adSizesJson.push([parseInt(adSize2[0]), parseInt(adSize2[1])]);
164                        }
165                        buildSlot(adElems[i], adSpecs, adSizesJson, adSlotId, adTarget);
166                    }
167                }
168            }); // end googletag.cmd.push
169        } // end if (adElems && adElems.length > 0)0
170        googletag.pubads().refresh(null, {changeCorrelator: true});
171
172        setupCommentsSection();
173    }
174
175    /**
176     * get adspecs and push to arrays and datalayer
177     */
178    function updateAdParams(){
179        adSpecs = getAdSpec();
180
181        adParams = {
182            pageLevelTargeting: {},
183        };
184
185        /**
186         * Parms Query Params into object
187         * @type {URLSearchParams}
188         */
189        const params = new Proxy(new URLSearchParams(window.location.search), {
190            get: (searchParams, prop) => searchParams.get(prop),
191        });
192
193        // Fetch from query to handle page caching
194        adSpecs.utm_medium = params.utm_medium;
195        adSpecs.utm_source = params.utm_source;
196        adSpecs.utm_content = params.utm_content;
197
198        adSpecs.di_inv = params['utm_di-inv'];
199
200        console.log("Checking DI Param: ", adSpecs.di_inv);
201    	// Directly use the global pvid variable. Since pvid is already defined as a global variable,
202        adParams.pageLevelTargeting['pvid'] = window.pvid;
203
204        function getCookie(name) {
205            const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
206            return match ? decodeURIComponent(match[2]) : null;
207        }
208
209
210        /**
211         * adParams Assignment - only add to array if value exists
212         */
213
214
215        adParamsAssign('targetingId', 'targeting_id');
216        adParamsAssign('page_id', 'page_id');
217        adParamsAssign('page_title', 'page_title');
218        adParamsAssign('page_tags', 'page_tags');
219        adParamsAssign('page_category', 'page_category');
220        adParamsAssign('page_category_id', 'page_category_ids');
221        adParamsAssign('zone', 'zone');
222       	adParamsAssign('pvid', 'pvid');
223        const cookieVal = getCookie('bionews_ut');
224        if (cookieVal) {
225            const data = JSON.parse(cookieVal);
226            adParams.pageLevelTargeting['bntid'] = '1';
227        } else {
228            adParamsAssign('bntid', 'bntid');
229        }
230
231        adParamsAssign('author', 'author');
232        adParamsAssign('utm_source', 'utm_source');
233        adParamsAssign('utm_medium', 'utm_medium');
234        adParamsAssign('utm_content', 'utm_content');
235        adParamsAssign('section', 'section');
236        adParamsAssign('archiveZone', 'archiveZone');
237        adParamsAssign('utm_di-inv', 'di_inv');
238
239        if(adSpecs.site_prefix) {
240            var pageIdPrefix = adSpecs.site_prefix + '-PAGE';
241            var sectionPrefix = adSpecs.site_prefix + '-SECTION';
242            var tagsPrefix = adSpecs.site_prefix + '-TAGS';
243
244            adParamsAssign(pageIdPrefix, 'page_id');
245            adParamsAssign(sectionPrefix, 'page_category');
246            adParamsAssign(tagsPrefix, 'page_tags');
247        }
248
249        // Set Target information for GTM in dataLayer
250        // console.log('pushing to data layer');
251        // console.log(adSpecs);
252        dataLayer.push(adSpecs);
253    }
254
255    /**
256     * Simple helper function for duplication reduction -- assign only if value exists
257     * uses var adParams / adSpecs defined above
258     * @param adParamsKey
259     * @param adSpecsKey
260     */
261    function adParamsAssign(adParamsKey, adSpecsKey){
262        // eliminate null,  undefined, or blank but keep false and 0
263        if (adSpecs[adSpecsKey] || adSpecs[adSpecsKey] === 0 || adSpecs[adSpecsKey] === false) {
264            adParams.pageLevelTargeting[adParamsKey] = adSpecs[adSpecsKey];
265        }
266    }
267
268    /**
269     * Setup comments toggle and handlers
270     */
271    function setupCommentsSection() {
272        const threadDiv = $('.bio-comment-thread__toggle');
273        if (threadDiv.length) {
274            threadDiv[0].onclick = function() {
275                const btn = $('.bio-comment-thread__toggle');
276                const commentsDiv = $('.bio-article-comments');
277                const btnText = $('.bio-comment-thread__text');
278                if (btn.hasClass('bio-comment-thread__toggle--open')) {
279                    commentsDiv.addClass("bio-comments--hidden");
280                    btn.removeClass('bio-comment-thread__toggle--open');
281                    btnText[0].innerText = "View";
282                    googletag.pubads().setTargeting("ugc", "false");
283                    googletag.pubads().refresh();
284                } else {
285                    commentsDiv.removeClass("bio-comments--hidden");
286                    btn.addClass('bio-comment-thread__toggle--open');
287                    btnText[0].innerText = "Hide";
288                    googletag.pubads().setTargeting("ugc", "true");
289                    googletag.pubads().refresh();
290                }
291            };
292        }
293    }
294    
295    /**
296     *
297     * @param adElems
298     * @param adSpecs
299     * @param adSizesJson
300     * @param adSlotId
301     * @param adTarget
302     */
303    function buildSlot(adElems, adSpecs, adSizesJson, adSlotId, adTarget) {
304        var isRefresh = false;
305        var pos = adElems.getAttribute('data-ad-pos');
306        adBlock = googletag.defineSlot(adSpecs.ad_unit + '/' + adTarget, adSizesJson, adSlotId)
307            .setTargeting('pos', pos)
308            .addService(googletag.pubads());
309
310        if (adElems.getAttribute('data-ad-refresh') == 'true') {
311            isRefresh = true;
312        }
313
314        activeAds.push({
315            elementId: adSlotId,
316            refresh: isRefresh,
317            adBlock
318        });
319    }
320
321    $(document).ready(function() {
322		//checkForBot();
323		getUserAgentInfo();
324		checkForBlacklistedUserAgent();
325        window.startAdScript();
326        var adSpecs = window.getAdSpec();
327        var cookieDate = new Date(new Date().getTime()+1000*60*60*24*365).toGMTString();
328
329
330        if(window.matchMedia("(max-width: 767px)").matches){
331            // show mobile popup after 3 seconds
332            var mobileDelay = getAdSpec().mobileDelay;
333            var d=new Date();
334            d.setTime(d.getTime()+(1*24*60*60*1000));
335            var expires = "; expires="+d.toGMTString();
336            var mobilePopCookie = $.bionews.getCookie('MOBILE_POPUP');
337            if(!mobilePopCookie && $('.bio-ad-block.mobile-pop-up .code-block').length ){
338                setTimeout(function(){
339                    $('.bio-ad-block.mobile-pop-up').addClass('visible');
340                    document.cookie = 'MOBILE_POPUP=true; ' + expires;
341                }, mobileDelay);
342            }
343        }
344        googletag.pubads().addEventListener('slotRequested', function(event) {
345            console.group('ads fetched');
346            console.log(event.slot.getSlotElementId(), 'fetched');
347            console.groupEnd('ad fetched');
348        });
349        googletag.pubads().addEventListener('slotOnload', function(event) {
350            console.group('ads rendered');
351            console.log(event.slot.getSlotElementId(), 'rendered');
352            console.groupEnd('ads rendered');
353            var adRefresh = adSpecs.adRefresh ? adSpecs.adRefresh : '30000';
354            var adSlotId = event.slot.getSlotElementId();
355            var adRefreshSet = $('#' + adSlotId).data('ad-refresh');
356            if(adRefreshSet == true) {
357                $('#' + adSlotId).data("timer",setTimeout(function() {
358                    if($('.ai-close.ai-close-fit')){
359                        googletag.pubads().refresh([ event.slot ]);
360                    }
361                },adRefresh));
362                $('.ai-close-button').on('click touch', function(e) {
363                    googletag.cmd.push(() => {
364                        googletag.destroySlots([ event.slot ]);
365                    });
366                })
367            }
368        });
369        googletag.pubads().addEventListener('slotRenderEnded', function(event) {
370            console.group('finished rendering ads');
371            console.log(event.slot.getSlotElementId(), 'finished rendering.');
372            console.groupEnd('finished rendering ads');
373            document.cookie = 'LAZY_LOAD=true; ' + expires;
374            if (event.slot) {
375                var slotId = event.slot.getSlotElementId();
376                if (event.isEmpty) {
377                    $('#' + slotId).hide().parent('.bio-ad').addClass('disabled').hide();
378                    $('#' + slotId).hide().parents('.bio-ad').addClass('disabled').hide();
379                } else {
380                    $('#' + slotId).prepend($('<div/>', {
381                        'class': 'adspot-title',
382                        'text': 'Advertisement'
383                    }));
384                }
385                var adRefreshSet = $('#' + slotId).data('ad-refresh');
386                if(adRefreshSet == true) {
387                    var floaterAd = $('#' + slotId + ' iframe').length;
388                    if(floaterAd <= 0) {
389                        var existCondition = setInterval(function() {
390                            if ($('.ai-close-fit').length) {
391                                clearInterval(existCondition);
392                                $('.ai-close.ai-close-fit').remove();
393                            }
394                        }, 100);
395
396                    }
397                }
398            }
399        });
400    });
401
402})(jQuery);

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.