PageSourceSearch

https://docstarclub.ru/nassets/a4fd5c80/auth.js?v=1765633901

js docstarclub.ru collected 2026-09-29 18:01:16 UTC 11,702 bytes, 434 lines download raw bytes

1/*jshint esversion: 6 */
2(function () {
3	'use strict';
4	let baseUrl = '';
5	const isIos = navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i);
6	const isMobile = navigator.userAgent.match(/Android/i)
7		|| navigator.userAgent.match(/webOS/i)
8		|| isIos;
9
10	let vkAuth = function (e) {
11
12		this.init = function(params) {
13
14			baseUrl = params[0];
15
16			let desktopUrl = 'https:' + baseUrl + '&isMobileApp=0';
17
18			if (!isMobile) {
19				//e.preventDefault();
20				const delayUrl = '/pl/vk/redirect/delay';
21				fetch(delayUrl, {
22					method: 'POST',
23					mode: 'cors',
24					cache: 'no-cache',
25					credentials: 'same-origin',
26					headers: {
27						'Content-Type': 'application/json'
28					},
29					redirect: 'follow',
30					referrerPolicy: 'no-referrer',
31					body: JSON.stringify({redirect: baseUrl})
32				}).then(() => {
33					window.location = desktopUrl;
34				}, error => {
35					console.log(error);
36				});
37			}
38		};
39	};
40
41	window.vkAuth = new vkAuth();
42})();
43
44var vkNativeApp = (function($) {
45	"use strict";
46	var Settings = {};
47	var AppLaunchStrategyParameters =  {
48		getAppUri : function() {
49			return 'https:' + Settings.url;
50		},
51		getAppLauncherEl : function() {
52			if (!Settings.appLauncherElId) {
53				throw new Error('Settings does not have valid appLauncherElId');
54			}
55			return $('#' + Settings.appLauncherElId);
56		},
57		getAppStoreURI: function() {
58			return 'https:' + Settings.url;
59		}
60	};
61
62	var AndroidAppLaunchStrategyParameters = $.extend({}, AppLaunchStrategyParameters, {
63		getIntentURI: function() {
64			return "intent:" + Settings.mobileUrl + "/#Intent;scheme=vk;package="+ Settings.androidAppId +";end";
65		},
66		getAppUri: function () {
67			return Settings.appUri;
68		},
69		getAppStoreURI: function () {
70			return "https:" + Settings.url;
71		}
72	});
73
74	var IOSAppLaunchStrategyParameters = $.extend({}, AppLaunchStrategyParameters, {
75		getAppStoreURI: function () {
76			return "https:" + Settings.url;
77		},
78		getUniversalLinkingUrl : function() {
79			return Settings.universalLinkUrl;
80		},
81		getAppUri : function() {
82			return Settings.appUri;
83		},
84	});
85
86	var AppLaunchStrategy = function (strategyParameters) {
87		this.strategyParameters = strategyParameters;
88		this.init = function(){};
89	};
90
91	var DirectAppOnlyLaunchStrategy = function(strategyParameters) {
92		this.init = function () {
93			var el = strategyParameters.getAppLauncherEl();
94			var appURI = strategyParameters.getAppUri();
95			el.click(function(e){
96				e.preventDefault();
97				window.location.reload();
98			});
99			window.location = appURI;
100		};
101	};
102
103	var DirectAppLaunchStrategy = function(strategyParameters) {
104		AppLaunchStrategy.call(this, strategyParameters);
105		var events = ["pagehide", "blur", "beforeunload"];
106		var timeout = null;
107		var preventDialog = function () {
108
109			clearTimeout(timeout);
110			timeout = null;
111			$(window).unbind(events.join(" "));
112		};
113
114		var el = strategyParameters.getAppLauncherEl();
115
116		var redirect = function () {
117			window.location = strategyParameters.getAppUri();
118			timeout = setTimeout(function() {
119				window.top.location = strategyParameters.getAppStoreURI();
120			}, 5000);
121		};
122
123		this.init = function() {
124			$(window).on("pagehide", preventDialog);
125			$(window).on("blur", preventDialog);
126			$(window).on("beforeunload", preventDialog);
127
128			el.unbind('click').on('click', function(e) {
129				e.preventDefault();
130				redirect();
131			});
132		};
133	};
134
135	var MiUIAppLaunchStrategy = function(strategyParameters) {
136		AppLaunchStrategy.call(this, strategyParameters);
137		const events = ["pagehide", "blur", "beforeunload"].join(" ");
138		let timeout = null;
139		const preventDialog = function () {
140			clearTimeout(timeout);
141			timeout = null;
142			$(window).off(events);
143		};
144
145		const el = strategyParameters.getAppLauncherEl();
146
147		const redirect = function () {
148			//редирект в приложение вк если установлено
149			window.location = strategyParameters.getAppUri();
150			timeout = setTimeout(function() {
151				// если не установлено, то через секунду редирект в браузере
152				window.top.location = strategyParameters.getAppStoreURI();
153			}, 1000);
154		};
155
156		this.init = function() {
157			$(window).on(events, preventDialog);
158			el.off('click').on('click', function(e) {
159				e.preventDefault();
160				redirect();
161			});
162		};
163	};
164
165	var CTAAppLaunchStrategy = function(strategyParameters) {
166		AppLaunchStrategy.call(this, strategyParameters);
167
168		this.init = function() {
169			var directStrategy = new DirectAppLaunchStrategy(strategyParameters);
170			var el = strategyParameters.getAppLauncherEl();
171			var id = el.attr('id');
172			$("body").on('click',  '#' + id, function(e) {
173				e.preventDefault();
174				directStrategy.init();
175			});
176		};
177	};
178
179	var CTAIntentAppLaunchStrategy = function(strategyParameters) {
180		AppLaunchStrategy.call(this, strategyParameters);
181
182		this.init = function() {
183			strategyParameters.
184			getAppLauncherEl().
185			attr('href', strategyParameters.getIntentURI());
186		};
187	};
188
189	var AppLaunchNotSupportedStrategy = function(strategyParameters) {
190		AppLaunchStrategy.call(this, strategyParameters);
191		this.init = function () {
192			const id = strategyParameters.getAppLauncherEl().attr('id');
193			$("body").on('click',  '#' + id, function(e) {
194				e.preventDefault();
195			});
196		};
197	};
198
199	function createCookie(name, value, second) {
200		var date = new Date();
201		date.setTime(date.getTime()+(second * 1000));
202		var expires = "; expires="+date.toGMTString();
203		document.cookie = name+"="+value+expires+"; path=/";
204	}
205
206	function readCookie(name) {
207		var nameEQ = name + "=";
208		var ca = document.cookie.split(';');
209		for(var i=0;i < ca.length;i++) {
210			var c = ca[i];
211			while (c.charAt(0) === ' ') {
212				c = c.substring(1,c.length);
213			}
214			if (c.indexOf(nameEQ) === 0) {
215				return c.substring(nameEQ.length,c.length);
216			}
217		}
218		return null;
219	}
220
221	function eraseCookie(name) {
222		createCookie(name,"",-1);
223	}
224
225	var UniversalLinkingAppLaunchStrategy = function(strategyParameters) {
226		var $cookieName = 'ul-app-detection-flag';
227		function appNotInstalled() {
228			return readCookie($cookieName) > 1;
229		}
230
231		function setCookie() {
232			var $cookieValue = readCookie($cookieName);
233			if (!$cookieValue || isNaN($cookieValue)) {
234				createCookie($cookieName, 1, 60);
235			} else {
236				createCookie($cookieName, 2, 60);
237			}
238		}
239
240		AppLaunchStrategy.call(this, strategyParameters);
241
242		this.init = function() {
243			var el = strategyParameters.getAppLauncherEl();
244			var $location = strategyParameters.getUniversalLinkingUrl();
245
246			if (appNotInstalled()) {
247				window.location = strategyParameters.getAppStoreURI();
248				eraseCookie();
249			}
250			el.attr('href', $location);
251
252			$(window).on('blur', function() {
253				eraseCookie($cookieName);
254			});
255
256			setCookie();
257			el.click(function() {
258				setCookie();
259			});
260		};
261	};
262
263	var BrowserChecker = function() {
264		var userAgent = window.navigator.userAgent.toLowerCase();
265
266		var isIOS = function() {
267			return /(?:i(?:phone|p(?:o|a)d))/.test(userAgent);
268		};
269
270		var iOSVersion = function() {
271			return isIOS() ? parseInt(userAgent.match(/os\s+(\d+)_/)[1], 10) : false;
272		};
273
274		var hasVersion = function() {
275			return userAgent.indexOf('version') > -1;
276		};
277
278		var appleWebKitVersion = function() {
279			var match = userAgent.match(/AppleWebKit\/([\d.]+)/);
280			return match ? parseFloat(match[1]) : false;
281		};
282
283		var isFacebook = function () {
284			return !!userAgent.match(/FBAV/i);
285		};
286
287		var isChrome = function () {
288			return userAgent.indexOf('chrome') > -1;
289		};
290
291		var chromeVersion = function () {
292			var raw = userAgent.match(/chrom(e|ium)\/([0-9]+)\./);
293			return raw ? parseInt(raw[2], 10) : false;
294		};
295
296		var isTwitter = function () {
297			return userAgent.indexOf('twitter') > -1;
298		};
299
300		var isInstagram = function () {
301			return userAgent.indexOf('instagram') > -1;
302		};
303
304		var isMiBrowser = function () {
305			return userAgent.indexOf('xiaomi/mi') > -1;
306		};
307
308		var isAndroid = function () {
309			return userAgent.indexOf('android') > -1;
310		};
311
312		var androidVersion = function() {
313			var match = userAgent.match(/android\s([\d.]*)/);
314			return match ? parseFloat(match[1]) : false;
315		};
316
317		var isAndroidStockBrowser = function() {
318			return isAndroid()
319				&& isChrome()
320				&& hasVersion()
321				&& !isFacebook(); // FB uses this browser, but deep links with custom URI scheme.
322
323		};
324
325		var isAndroidNativeBrowser = function() {
326			return !isFacebook()
327				&& (isAndroid() && (appleWebKitVersion() && appleWebKitVersion() < 537)
328					||
329					(chromeVersion() && chromeVersion() < 37));
330		};
331
332		return {
333			isIOS: isIOS(),
334			iOSVersion: iOSVersion(),
335			isAndroid: isAndroid(),
336			androidVersion: androidVersion(),
337			isAndroidStockBrowser: isAndroidStockBrowser(),
338			isAndroidNativeBrowser: isAndroidNativeBrowser(),
339			isFacebook: isFacebook(),
340			isChrome: isChrome(),
341			isTwitter: isTwitter(),
342			isInstagram: isInstagram(),
343			isMiBrowser: isMiBrowser(),
344		};
345	};
346
347	var AppLaunchStrategyParameterFactory = function() {
348		var strategyParameters = AppLaunchStrategyParameters;
349
350		if (BrowserChecker().isIOS) {
351			strategyParameters = IOSAppLaunchStrategyParameters;
352		} else if (BrowserChecker().isAndroid) {
353			strategyParameters = AndroidAppLaunchStrategyParameters;
354		}
355		return strategyParameters;
356	};
357
358	var AppLaunchStrategyFactory = function (strategyType) {
359		var strategyParameters = AppLaunchStrategyParameterFactory();
360		var appLaunchStrategy;
361		if (strategyType === 'cta' || strategyType === undefined) {
362			appLaunchStrategy = new CTAAppLaunchStrategy(strategyParameters);
363		} else if(strategyType === 'direct') {
364			appLaunchStrategy = new DirectAppLaunchStrategy(strategyParameters);
365		} else if (strategyType === 'ul') {
366			appLaunchStrategy =  new UniversalLinkingAppLaunchStrategy(strategyParameters);
367		} else if (strategyType === 'mi') {
368			appLaunchStrategy =  new MiUIAppLaunchStrategy(strategyParameters);
369		} else if (strategyType === 'notsupported') {
370			appLaunchStrategy =  new AppLaunchNotSupportedStrategy(strategyParameters);
371		} else if (strategyType === 'directapponly') {
372			appLaunchStrategy =  new DirectAppOnlyLaunchStrategy(strategyParameters);
373		} else if (strategyType === 'intent_cta') {
374			appLaunchStrategy =  new CTAIntentAppLaunchStrategy(strategyParameters);
375		} else {
376			throw new Error('Deeplinking: Unsupported deeplinking strategy type');
377		}
378
379		return appLaunchStrategy;
380	};
381
382	var AppLauncherFactory = function() {
383		var browser = BrowserChecker();
384
385		var deepLinkingStrategy = new AppLaunchStrategyFactory('cta');
386
387		if (browser.isInstagram) {
388			return new AppLaunchStrategyFactory('direct');
389		}
390
391		if (browser.isMiBrowser) {
392			return new AppLaunchStrategyFactory('mi');
393		}
394
395		if (browser.isIOS) {
396			if (browser.iOSVersion < 9) {
397				deepLinkingStrategy = new AppLaunchStrategyFactory('direct');
398				if (browser.isTwitter) {
399					deepLinkingStrategy = new AppLaunchStrategyFactory('directapponly');
400				}
401			} else {
402				deepLinkingStrategy = new AppLaunchStrategyFactory('direct');
403				if (browser.isFacebook) {
404					deepLinkingStrategy = new AppLaunchStrategyFactory('ul');
405				}
406			}
407		} else if (browser.isAndroid) {
408			deepLinkingStrategy = new AppLaunchStrategyFactory('intent_cta');
409			if (browser.isAndroidNativeBrowser || browser.isAndroidStockBrowser) {
410				deepLinkingStrategy = new AppLaunchStrategyFactory('notsupported');
411			}
412		}
413
414		return deepLinkingStrategy;
415	};
416
417	var Init = function (settings) {
418		Settings = settings;
419		setTimeout(function() {
420			return AppLauncherFactory().init();
421		}, 1000);
422
423	};
424
425	var Utils = {};
426
427	return {
428		init: Init,
429		browserChecker: BrowserChecker,
430		util: Utils,
431		androidParameters: AndroidAppLaunchStrategyParameters,
432		iOSParameters:IOSAppLaunchStrategyParameters
433	};
434})(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.