PageSourceSearch

https://vallummag.com/wp-content/plugins/super-progressive-web-apps/public/js/register-sw.js?ver=1790855905

js vallummag.com collected 2026-10-01 11:59:31 UTC 10,622 bytes, 286 lines download raw bytes

1if ('serviceWorker' in navigator) {
2  window.addEventListener('load', function() {
3	navigator.serviceWorker.register(superpwa_sw.url)
4	.then(function(registration) { console.log('SuperPWA service worker ready'); 
5		if(registration.active)
6		{
7			registration.update(); 
8		}
9		if(typeof firebase !='undefined' && typeof pushnotification_load_messaging =='function'){
10			const messaging = firebase.messaging();
11			messaging.useServiceWorker(registration);
12			pushnotification_load_messaging();
13		}
14		subOnlineOfflineIndicator();
15	})
16	.catch(function(error) { console.log('Registration failed with ' + error); });
17
18	/****************** Start : Online/Offline Indicator ******************/
19
20	// Variables & default values
21	const snackbarTimeToHide = 5000; // 5s
22	let isOffline = false,
23		snackbarTimeoutHide = null,
24		goOfflineMsg = 'You\'re currently offline',
25		backOnlineMsg = 'You\'re back online <a href="javascript:location.reload()">refresh</a>';
26
27	/**
28	* Subscribe to online offline indicator
29	*/
30	function subOnlineOfflineIndicator() {
31		injectSnackbarHtml();
32		injectSnackbarCss();
33		runOnlineOfflineIndicator();
34	}
35
36	/**
37 	* Inject html of snackbar
38 	*/
39	function injectSnackbarHtml() {
40		const container = document.createElement('div');
41		container.className = 'snackbar';
42
43		const parag = document.createElement('p');
44		parag.id = 'snackbar-msg';
45		container.appendChild(parag);
46
47		const button = document.createElement('button');
48		button.type = 'button';
49		button.className = 'snackbar-close';
50		button.setAttribute('aria-label', 'Close ×');
51		button.addEventListener('click', hideSnackbar);
52		button.innerHTML = '&times;';
53
54		container.appendChild(button);
55
56		document.body.appendChild(container);
57
58		window.addEventListener('online', runOnlineOfflineIndicator);
59		window.addEventListener('offline', runOnlineOfflineIndicator);
60
61		window.addEventListener('fetch',() => console.log("fetch"));
62
63		// Clean snackbarTimeToHide varibale when user hover on the snackbar to prevent hide it
64		container.addEventListener('mouseover', function () {
65			if (snackbarTimeoutHide !== null)
66				clearTimeout(snackbarTimeoutHide);
67		});
68
69		// Call setTimeout and set snackbarTimeToHide variable to hide snackbar
70		container.addEventListener('mouseout', function () {
71			if (snackbarTimeoutHide !== null)
72				snackbarTimeoutHide = setTimeout(hideSnackbar, snackbarTimeToHide / 2);
73		});
74	}
75
76	/**
77 	* Inject style css of snackbar
78 	*/
79	function injectSnackbarCss() {
80		const css = `body.snackbar--show .snackbar {
81			-webkit-transform: translateY(0);
82			transform: translateY(0); 
83		}
84		.snackbar {
85			box-sizing: border-box;
86			background-color: #121213;
87			color: #fff;
88			padding: 10px 55px 10px 10px;
89			position: fixed;
90			z-index: 9999999999999999;
91			left: 15px;
92			bottom: 15px;
93			border-radius: 5px 8px 8px 5px;
94			max-width: 90%;
95			min-height: 48px;
96			line-height: 28px;
97			font-size: 16px;
98			-webkit-transform: translateY(150%);
99			transform: translateY(150%);
100			will-change: transform;
101			-webkit-transition: -webkit-transform 200ms ease-in-out;
102			-webkit-transition-delay: 0s;
103					transition-delay: 0s;
104			-webkit-transition: -webkit-transform 200ms ease-in-out false;
105			transition: -webkit-transform 200ms ease-in-out false;
106			transition: transform 200ms ease-in-out false;
107			transition: transform 200ms ease-in-out false, -webkit-transform 200ms ease-in-out false; 
108		}
109		.snackbar p {
110			margin: 0;
111			color: #fff;
112			text-align: center; 
113		}
114		.snackbar .snackbar-close {
115			position: absolute;
116			top: 0;
117			right: 0;
118			width: 45px;
119			height: 100%;
120			padding: 0;
121			background: #2a2a2a;
122			border: none;
123			font-size: 28px;
124			font-weight: normal;
125			border-radius: 0 5px 5px 0;
126			color: #FFF;
127			font-family: Arial, Helvetica, sans-serif;
128		}
129		.snackbar .snackbar-close:hover,
130		.snackbar .snackbar-close:focus {
131			background: #3f3f3f;
132		}
133		.snackbar a {
134			color: #FFF;
135			font-weight: bold;
136			text-decoration: underline; 
137		}`;
138			
139		const head = document.head || document.getElementsByTagName('head')[0];
140		const style = document.createElement('style');
141
142		style.type = 'text/css';
143		if (style.styleSheet) {
144			// This is required for IE8 and below.
145			style.styleSheet.cssText = css;
146		} else {
147			style.appendChild(document.createTextNode(css));
148		}
149
150		head.appendChild(style);
151	}
152
153	/**
154 	* Show the state of the mode of connectivity to the user :  back onLine | go offLine
155 	*/
156	function runOnlineOfflineIndicator() {
157		if (navigator.onLine) {
158			if (isOffline === true) {
159				showSnackbar(backOnlineMsg);
160			}
161			isOffline = false;
162		} else {
163			showSnackbar(goOfflineMsg);
164			isOffline = true;
165		}
166	}
167
168	/**
169 	* Show with the given message in the snackbar
170 	* @param {String} msg 
171 	*/
172	function showSnackbar(msg) {
173		document.getElementById('snackbar-msg').innerHTML = msg;
174		document.body.classList.add('snackbar--show');
175
176		clearTimeout(snackbarTimeoutHide);
177		snackbarTimeoutHide = setTimeout(hideSnackbar, snackbarTimeToHide);
178	}
179
180	/**
181	* Hide snackbar
182	*/
183	function hideSnackbar() {
184		document.body.classList.remove('snackbar--show');
185	}
186
187	/****************** End : Online/Offline Indicator ******************/
188
189	var deferredPrompt;
190	window.addEventListener('beforeinstallprompt', function(e){
191		deferredPrompt = e;
192		if(deferredPrompt != null || deferredPrompt != undefined){
193			if(superpwa_sw.disable_addtohome==1){
194				deferredPrompt.preventDefault();
195			}
196
197			var a2hsBanner = document.getElementsByClassName("superpwa-sticky-banner");
198			if(a2hsBanner.length){
199				deferredPrompt.preventDefault();
200				//Disable on desktop
201				if(superpwa_sw.enableOnDesktop!=1 && !window.mobileCheck()){return ;}
202				if(typeof super_check_bar_closed_or_not == 'function' && !super_check_bar_closed_or_not()){return ;}
203				for (var i = 0; i < a2hsBanner.length; i++) {
204					var showbanner = a2hsBanner[i].getAttribute("data-show");
205					a2hsBanner[i].style.display="flex";
206				}
207			}
208			document.cookie = "hidecta=no";
209		}
210	})
211
212window.addEventListener('appinstalled', function(evt){
213		var a2hsBanner = document.getElementsByClassName("superpwa-sticky-banner");
214		if(a2hsBanner.length){
215			for (var i = 0; i < a2hsBanner.length; i++) {
216				var showbanner = a2hsBanner[i].getAttribute("data-show");
217					    document.cookie = "hidecta=yes";
218					a2hsBanner[i].style.display="none";
219			    }
220			}
221	});
222	
223	var a2hsviaClass = document.getElementsByClassName("superpwa-add-via-class");
224    if(a2hsviaClass !== null){
225        for (var i = 0; i < a2hsviaClass.length; i++) {
226          a2hsviaClass[i].addEventListener("click", addToHome); 
227      }
228    }
229
230    function addToHome(){
231		if(!deferredPrompt){return ;}
232		deferredPrompt.prompt(); 
233		deferredPrompt.userChoice.then(function(choiceResult) {
234			if (choiceResult.outcome === "accepted") {
235				var a2hsBanner = document.getElementsByClassName("superpwa-sticky-banner");
236				if(a2hsBanner){
237					for (var i = 0; i < a2hsBanner.length; i++) {
238						var showbanner = a2hsBanner[i].getAttribute("data-show");
239						a2hsBanner[i].style.display="none";
240					}
241				}//a2hsBanner if
242				console.log("User accepted the prompt");
243			}else{
244				console.log("User dismissed the prompt");
245			}
246			deferredPrompt = null;
247		});
248	} // function closed addToHome
249
250
251  });
252}
253window.mobileCheck = function() {
254	  let check = false;
255	  (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check 
255= true;})(navigator.userAgent||navigator.vendor||window.opera);
256	  return check;
257	};
258
259 window.addEventListener('load', function() {
260     var manifestLink = document.querySelectorAll("link[rel='manifest']");
261	    if(manifestLink.length > 1){
262	        for (var i = 0; i < manifestLink.length; i++) {
263	        	var href = manifestLink[i].getAttribute("href");
264	        	if(href.indexOf("superpwa-manifest.json") == -1){
265                     manifestLink[i].remove();
266	        	}
267	        }
268	    }
269		// fix for href="#" in Ios safari standalone
270		var ua = window.navigator.userAgent;
271		var iOS = ua.match(/iPad/i) || ua.match(/iPhone/i);
272		var webkit = ua.match(/WebKit/i);
273		var iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
274
275		if(iOSSafari && (window.matchMedia('(display-mode: standalone)').matches)){
276		setTimeout(function(){
277			const anchor_fix = document.querySelectorAll("a[href='#']");
278			if(anchor_fix.length > 1){
279				for (var i = 0; i < anchor_fix.length; i++) {
280				 anchor_fix[i].setAttribute("href","javascript:void(0);");
281				}
282			}
283		},600);
284	}
285
286 });

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.