PageSourceSearch

https://www.iol.pt/firebase-messaging-sw.js

js iol.pt collected 2026-09-24 08:27:36 UTC 7,635 bytes, 194 lines download raw bytes

1let conversionUrl = 'https://externalservices.iol.pt/notification-producer/v1/conversion?target=WEB&id=';
2let receptionUrl = 'https://externalservices.iol.pt/notification-producer/v1/reception?target=WEB&id=';
3let lastContentId, firebaseConfig;
4
5self.addEventListener('notificationclick', function(e) {
6	e.notification.close();
7	var promise = new Promise(function(resolve) {
8		resolve();
9	}).then(function() {
10		fetch(conversionUrl + e.notification.data.notiId);
11		return clients.openWindow(e.notification.data.target ? e.notification.data.target : e.notification.data.FCM_MSG.data.target);
12	});
13	e.waitUntil(promise);
14});
15
16self.addEventListener('install', function(event) {
17	  // The promise that skipWaiting() returns can be safely ignored.
18	  self.skipWaiting();
19});
20
21if ('function' === typeof importScripts) {
22	importScripts('https://www.gstatic.com/firebasejs/7.15.4/firebase-app.js');
23	importScripts('https://www.gstatic.com/firebasejs/7.15.4/firebase-messaging.js');
24	importScripts('https://www.gstatic.com/firebasejs/7.15.4/firebase-auth.js');
25	try {
26		let site = new URL(location).searchParams.get('site').toLowerCase();
27		if(site.toLowerCase() === 'cnn'){
28            firebaseConfig = {
29                apiKey: "AIzaSyD9e2KAhRVi1XvFzXSMKzL67zbrP03EX2o",
30                authDomain: "cnn-portugal-web-e-apps.firebaseapp.com",
31                projectId: "cnn-portugal-web-e-apps",
32                storageBucket: "cnn-portugal-web-e-apps.appspot.com",
33                messagingSenderId: "434957535894",
34                appId: "1:434957535894:web:49202a5cde02ac176a10b7",
35                measurementId: "G-DDNN4DERKM"
36            };
37        } else if(site === 'maisfutebol'){
38			 firebaseConfig = {
39					apiKey: "AIzaSyBpXhMRLzZMUrI-4hWe4PhyDV0ypKJoOfI",
40					authDomain: "maisfutebol-web-e-app.firebaseapp.com",
41					databaseURL: "https://maisfutebol-web-e-app.firebaseio.com",
42					projectId: "maisfutebol-web-e-app",
43					storageBucket: "maisfutebol-web-e-app.appspot.com",
44					messagingSenderId: "677672555470",
45					appId: "1:677672555470:web:39cf2193ae864b03c0519f",
46					measurementId: "G-DP1STDS1WB"
47			};
48		} else if(site === 'tvi24') {
49			firebaseConfig = {
50				    apiKey: "AIzaSyCNVT7-Ock0K7eSZvN9XkDVoxEoKjEXuOA",
51				    authDomain: "tvi-24-web-e-apps.firebaseapp.com",
52				    databaseURL: "https://tvi-24-web-e-apps.firebaseio.com",
53				    projectId: "tvi-24-web-e-apps",
54				    storageBucket: "tvi-24-web-e-apps.appspot.com",
55				    messagingSenderId: "87360395482",
56				    appId: "1:87360395482:web:87365a2e2521b5ffbf6de3",
57				    measurementId: "G-88QW5YV6G1"
58				  };
59		} else if(site.toLowerCase() === 'away') {
60			firebaseConfig = 	{
61				apiKey: "AIzaSyAWKhsm1I6BJtBapy5MKMsniYvLmq9NJNU",
62				authDomain: "away-6cc6e.firebaseapp.com",
63				projectId: "away-6cc6e",
64				storageBucket: "away-6cc6e.appspot.com",
65				messagingSenderId: "132903327115",
66				appId: "1:132903327115:web:4426e13ee0d018a7188b8e",
67				measurementId: "G-W2DQ8DG3W8"
68			  };
69		} else if(site.toLowerCase() === 'bigbrother') {
70			firebaseConfig = 	{
71				apiKey: "AIzaSyASMxHVRtZK3fg5HkEjtHMhVCHKJa2JJL4",
72				authDomain: "big-brother-e74e7.firebaseapp.com",
73				databaseURL: "https://big-brother-e74e7.firebaseio.com",
74				projectId: "big-brother-e74e7",
75				storageBucket: "big-brother-e74e7.appspot.com",
76				messagingSenderId: "1080686009193",
77				appId: "1:1080686009193:web:510ad337cc2e0cda74fbf8",
78				measurementId: "G-YHE5K43RQR"
79			  };
80		} else if(site.toLowerCase() === 'tvireality') {
81			firebaseConfig = {
82				apiKey: "AIzaSyBHT3t_Q9Nyf9iu97vuFvG71M8u2oarx7I",
83				authDomain: "tvi-reality.firebaseapp.com",
84				projectId: "tvi-reality",
85				storageBucket: "tvi-reality.appspot.com",
86				messagingSenderId: "519173930754",
87				appId: "1:519173930754:web:f935ddbb60bcf7bb020c1b",
88				measurementId: "G-PZKQGENDC2"
89			  };
90		} else if(site.toLowerCase() === 'iol') {
91			firebaseConfig = 	{
92				apiKey: "AIzaSyAD4U1HfNwxdvnDf5Vdhmd6qNkCTT7CaHM",
93				authDomain: "portal-iol.firebaseapp.com",
94				projectId: "portal-iol",
95				storageBucket: "portal-iol.appspot.com",
96				messagingSenderId: "160865623587",
97				appId: "1:160865623587:web:e02771bbdd619ea482db96",
98				measurementId: "G-TBSQB515C1"
99			  };
100		} else if(site.toLowerCase() === 'tvi') {
101			firebaseConfig = {
102				apiKey: "AIzaSyBLhV87IuxQJHcBrOvy5Y7-fGoH58s-RpQ",
103				authDomain: "tvi-web-e-app.firebaseapp.com",
104				databaseURL: "https://tvi-web-e-app.firebaseio.com",
105				projectId: "tvi-web-e-app",
106				storageBucket: "tvi-web-e-app.appspot.com",
107				messagingSenderId: "1080082584195",
108				appId: "1:1080082584195:web:ef01d943bcbd640d6381b6"
109			};
110		} else if(site.toLowerCase() === 'versa') {
111			firebaseConfig = {
112				apiKey: "AIzaSyDqvtSJ0lLu9f8QuxTLkR9CGJBeDXsS2IY",
113				authDomain: "versa-2bb2d.firebaseapp.com",
114				projectId: "versa-2bb2d",
115				storageBucket: "versa-2bb2d.appspot.com",
116				messagingSenderId: "186587587629",
117				appId: "1:186587587629:web:f4b54d27c3b946d40e04a4",
118				measurementId: "G-3PJZWWZ21D"
119			};
120		} else if(site.toLowerCase() === 'selfie') {
121			firebaseConfig = {
122				apiKey: "AIzaSyDKzX-JSADlFaXj5GFvVJS6k8n6H5AEUVc",
123				authDomain: "selfie-525fe.firebaseapp.com",
124				projectId: "selfie-525fe",
125				storageBucket: "selfie-525fe.appspot.com",
126				messagingSenderId: "160520720540",
127				appId: "1:160520720540:web:d1809117a5d8ab745c1d59",
128				measurementId: "G-F6BWF16FQC"
129			};
130		} else if(site.toLowerCase() === 'sol') { 
131			firebaseConfig = {
132				apiKey: "AIzaSyAKDEKhKKg2XGdsW0eHbWb5rXmM2XyMCgU",
133				authDomain: "sol-web-bf2a4.firebaseapp.com",
134				projectId: "sol-web-bf2a4",
135				storageBucket: "sol-web-bf2a4.firebasestorage.app",
136				messagingSenderId: "691516853014",
137				appId: "1:691516853014:web:d2669b9bcdec123e2b1e37",
138				measurementId: "G-MWNTK2BFGC"
139			}
140		} else {
141			firebaseConfig = {
142					apiKey: "AIzaSyAaXGxfdbLNT9D6_rz7blyWKhEzNHU2JQ8",
143					authDomain: "tviplayer-web-e-app.firebaseapp.com",
144					databaseURL: "https://tviplayer-web-e-app.firebaseio.com",
145					projectId: "tviplayer-web-e-app",
146					storageBucket: "tviplayer-web-e-app.appspot.com",
147					messagingSenderId: "566186928211",
148					appId: "1:566186928211:web:2b0595dfdd11550307fea6",
149					measurementId: "G-E71K5PWG1M"
150			};
151		}
152		firebase.initializeApp(firebaseConfig);
153		const messaging = firebase.messaging();
154		messaging.setBackgroundMessageHandler(function(payload) {
155			let notiOptions = {
156				body : payload.data.body,
157				tag: payload.data.notiId,
158				badge: payload.data.badge,
159	            icon: payload.data.icon,
160				image: payload.data.img,
161				data : {
162					target : payload.data.target,
163					notiId : payload.data.notiId,
164				},
165			/*
166			 * actions: [ { action: 'explore', title: 'Ver o artigo', }, { action: 'close', title: 'Outra O', }, ]
167			 */
168			}
169			if (payload.data.notiId || true) {
170				lastContentId = payload.data.notiId;
171				//registerReception(payload.data.notiId);
172				return self.registration.showNotification(payload.data.title, notiOptions);
173			}
174		});
175	} catch (e) {
176		console.log("Erro ao instanciar o SW (firebase-messaging-sw.js)")
177	}
178}
179async function registerReception(notificationId){
180    // para evitar DDOS, manda o recibdo num tempo aleatorio entre 1s e 1 minuto
181    let time = Math.floor(Math.random() * (60000 - 1000 + 1)) + 1000;
182    setTimeout(function () {
183    fetch(receptionUrl + notificationId).then(function(response) {
184        if (!response.ok) {
185            throw Error(response.statusText);
186        }
187    }).catch(function(error) {
188    	// caso falhe retry a cada 10 segundos
189    	setTimeout(function(){
190    		registerReception(notificationId);
191    	}, 10000);
192    });
193  }, time);
194}

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.