<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Redirecting…</title>

		<style>
			:root {
				background: #fafaff;
				color: #337;
				font-family: sans-serif;
				text-align: center;
				display: grid;
				height: 100svh;
				width: 100vw;
				justify-content: center;
				align-items: center;
			}

			a {
				color: #559fff;
			}

			div {
				display: contents;
			}
		</style>
	</head>
	<body>
		<noscript>
			<style>
				div {
					display: none;
				}
			</style>

			<p>JavaScript is required</p>
		</noscript>

		<div>
			<h1>Redirecting…</h1>
			<p>If redirect does not happen automatically, <a>click here</a></p>
		</div>

		<script>
			const siteMap = {
				'nwi.life': 'nwi',
				'valpo.life': 'valpo',
				'valpolife.com': 'valpo',
				'portage.life': 'portage',
				'portagelife.com': 'portage',
				'laportecounty.life': 'laportecounty',
				'laportecountylife.com': 'laportecounty',
				'michiana.life': 'michiana',
			};

			function isSupportedDomain(domain) {
				return Object.keys(siteMap).includes(domain);
			}

			const botList = [
				'AdsBot-Google',
				'AI2Bot',
				'Ai2Bot-Dolma',
				'Amazonbot',
				'anthropic-ai',
				'Applebot',
				'Applebot-Extended',
				'AwarioRssBot',
				'AwarioSmartBot',
				'Brightbot 1.0',
				'Bytespider',
				'CCBot',
				'ChatGPT',
				'ChatGPT-User',
				'Claude-Web',
				'ClaudeBot',
				'cohere-ai',
				'cohere-training-data-crawler',
				'Crawlspace',
				'DataForSeoBot',
				'Diffbot',
				'DuckAssistBot',
				'FacebookBot',
				'FeedFetcher',
				'Feedly',
				'FriendlyCrawler',
				'Google-Extended',
				'GoogleOther',
				'GoogleOther-Image',
				'GoogleOther-Video',
				'GPTBot',
				'iaskspider/2.0',
				'ICC-Crawler',
				'ImagesiftBot',
				'img2dataset',
				'ISSCyberRiskCrawler',
				'leakix',
				'Kangaroo Bot',
				'magpie-crawler',
				'Meta-ExternalAgent',
				'Meta-ExternalFetcher',
				'OAI-SearchBot',
				'omgili',
				'omgilibot',
				'PanguBot',
				'peer39_crawler',
				'PerplexityBot',
				'PetalBot',
				'Scrapy',
				'SemrushBot',
				'Sidetrade indexer bot',
				'Timpibot',
				'VelenPublicWebCrawler',
				'Webzio-Extended',
				'YouBot',
			];

			(() => {
				const url = new URL(window.location);
				const userAgent = navigator.userAgent;

				if (userAgent === '' || userAgent === null) {
					window.location = '/404.html';
					return;
				} else {
					for (const bot of botList) {
						if (userAgent.toLowerCase().match(bot.toLowerCase())) {
							window.location = '/404.html';
							return;
						}
					}
				}

				const hostname = url.hostname;
				const originatingDomain = Object.keys(siteMap).find(name => hostname.endsWith(name));

				if (!originatingDomain || !isSupportedDomain(originatingDomain)) {
					window.location = '/404.html';
					return;
				}

				const extension = url.pathname.split('.').pop().toLowerCase();
				const mediaExtensions = /avif|bmp|gif|hei[cf]|ico|jpe?g|png|svg|tiff?|webp/;

				if (mediaExtensions.test(extension)) {
					window.location = '/404.html';
					return;
				}

				const targetUrl = new URL(url);

				targetUrl.hostname = 'greatnews.life';
				targetUrl.port = '';
				targetUrl.searchParams.append('region', siteMap[originatingDomain]);

				document.querySelector('a').href = targetUrl.toString();
				window.location = targetUrl.toString();
			})();
		</script>
	</body>
</html>
