PageSourceSearch

https://hamgardi.com/sw.js

js hamgardi.com collected 2026-10-02 10:58:09 UTC 10,037 bytes, 277 lines download raw bytes

1importScripts('https://www.gstatic.com/firebasejs/7.3.0/firebase-app.js');
2
3var firebaseConfig = {
4    apiKey: "AIzaSyBF-Xi4yba4NyeBA_LmlTkTOlAVw1DKuHs",
5    authDomain: "tidy-amplifier-542.firebaseapp.com",
6    databaseURL: "https://tidy-amplifier-542.firebaseio.com",
7    projectId: "tidy-amplifier-542",
8    storageBucket: "tidy-amplifier-542.appspot.com",
9    messagingSenderId: "1051783534083",
10    appId: "1:1051783534083:web:21ba0821f4ae150f0aa036"
11};
12// Initialize Firebase
13firebase.initializeApp(firebaseConfig);
14
15self.addEventListener('push', function (e) {
16    var data = {};
17    if (e.data) {
18        data = e.data.json();
19    }
20
21    if (typeof data.data["gcm.notification.remote_notificationModel"] !== "undefined") {
22        var remote_notificationModel = JSON.parse(data.data["gcm.notification.remote_notificationModel"]);
23        var remoteURL = 'fa/Ajax/FirebaseCloudMessaging/GetNotification?';
24        for (var i = 0; i < remote_notificationModel.fetchParameters.length; i++) {
25            remoteURL += remote_notificationModel.fetchParameters[i].Key + '=' + remote_notificationModel.fetchParameters[i].Value + '&';
26        }
27        e.waitUntil(fetch(remoteURL)
28            .then(function (response) {
29                return response.json();
30            })
31            .then(function (data) {
32                if (data.success && data.model) {
33
34                    var notificationParser = new NotificationParser(data.model);
35                    var option = notificationParser.getNotificationOptions();
36                    if (option !== null) {
37
38                        return self.registration.showNotification(data.model["title"] || "Hamgardi",
39                            option);
40                    }
41                }
42            }));
43    }
44    else if (typeof data.data["gcm.notification.model"] !== "undefined") {
45        var notificationModel = JSON.parse(data.data["gcm.notification.model"]);
46
47        var notificationParser = new NotificationParser(notificationModel);
48        var option = notificationParser.getNotificationOptions();
49        if (option !== null) {
50            e.waitUntil(
51                self.registration.showNotification(notificationModel["title"] || "Hamgardi",
52                    option));
53        }
54    }
55});
56
57self.addEventListener('notificationclick', function (e) {
58    var action = (e.action ? JSON.parse(e.action) : e.notification.data.action);
59    if (typeof action !== "undefined" && action !== null) {
60        switch (action.actionType) {
61            case NotificationStatic.ActionTypes.openLink:
62            case NotificationStatic.ActionTypes.openWebview:
63                clients.openWindow(action.href);
64                break;
65            case NotificationStatic.ActionTypes.openSelf:
66                clients.openWindow('/');
67                break;
68            case NotificationStatic.ActionTypes.closeNotification:
69                e.notification.close();
70                break;
71            default:
72        }
73    }
74});
75
76function NotificationParser(model) {
77    this.model = model;
78
79    //Return Model, Abort
80    this.getNotificationOptions = function (model) {
81        var _this = this;
82        if (typeof model === "undefined")
83            model = this.model;
84
85        var fallBack = this.propNotNull(model, "fallBack") ? model.fallBack : null;
86
87        if (this.propNotNull(model, "conditions") && model.conditions.length > 0) {
88            var conditions_result = "Valid";
89            model.conditions.forEach(function (item) {
90                conditions_result = _this.validateCondition(item);
91                if (conditions_result !== "Valid")
92                    return;
93            });
94
95            if (conditions_result !== "Valid") {
96                var conditions_fallBackType = model.conditions_fallBackType;
97
98                return this.handleFallBack(conditions_fallBackType, fallBack, "getNotificationOptions", true);
99            }
100        }
101
102
103        var buttons = [];
104        //Check FallBack needed
105        if (this.propNotNull(model, "buttons") && model.buttons.length > 0) {
106            var buttons_fallBackType = model.buttons_fallBackType;
107            var abort_buttons = false;
108            model.buttons.forEach(function (button) {
109                var b = _this.getFinalActionModel(button);
110                if (b !== "Ignore" && b !== "Abort")
111                    buttons.push(b);
112                else if (b === "Abort") {
113                    abort_buttons = true;
114                    return;
115                }
116            });
117
118            if (abort_buttons) {
119                return this.handleFallBack(buttons_fallBackType, fallBack, "getNotificationOptions", true);
120            }
121
122            model.buttons = buttons;
123
124            if (model.buttons.length > 0) {
125                if (!('actions' in Notification.prototype)) {
126                    return this.handleFallBack(buttons_fallBackType, fallBack, "getNotificationOptions", true);
127                }
128            }
129        }
130
131        var options = {
132            dir: "auto",
133            body: model["body"] || null,
134            icon: model["icon"] || null,
135            tag: model["tag"] || null,
136            badge: model["badge"] || null,
137            image: model["image"] || null,
138            renotify: model["renotify"] || false,
139            requireInteraction: model["requireInteraction"] || false,
140            silent: !model["sound"],
141            timestamp: model["timestamp"] || null,
142            vibrate: model["sound"] ? (model["vibrate_pattern"] || null) : null
143        };
144        options.data = { action: null };
145        if (this.propNotNull(model, "action")) {
146            var action_fallBackType = model.action_fallBackType;
147            var b = _this.getFinalActionModel(model.action);
148            if (b !== "Ignore" && b !== "Abort") {
149                options.data.action = b;
150            }
151            else if (b === "Abort") {
152                return this.handleFallBack(action_fallBackType, fallBack, "getNotificationOptions", true);
153            }
154        }
155
156        //actions
157        if (this.propNotNull(model, "buttons") && model.buttons.length > 0) {
158            options.actions = [];
159            model.buttons.forEach(function (button) {
160                var action = {
161                    title: button["title"] || "Click",
162                    icon: button["icon"] || null,
163                    action: JSON.stringify(button)
164                };
165                options.actions.push(action);
166            });
167        }
168
169        for (var propName in options) {
170            if (options[propName] === null || typeof options[propName] === "undefined") {
171                delete options[propName];
172            }
173        }
174
175        return options;
176    };
177
178    //Return ActionModel, Ignore , Abort
179    this.getFinalActionModel = function (button) {
180        var _this = this;
181        var fallBack = this.propNotNull(button, "fallBack") ? button.fallBack : null;
182        var fallBackType = button.fallBackType;
183
184        var conditions_result = "Valid";
185        if (this.propNotNull(button, "conditions") && button.conditions.length > 0) {
186            button.conditions.forEach(function (item) {
187                conditions_result = _this.validateCondition(item);
188                if (conditions_result !== "Valid")
189                    return;
190            });
191        }
192        if (conditions_result !== "Valid")
193            return this.handleFallBack(fallBackType, fallBack, "getFinalActionModel", false);
194
195
196
197        var valid = true;
198        var validActionTypes = [
199            NotificationStatic.ActionTypes.openLink,
200            NotificationStatic.ActionTypes.openSelf,
201            NotificationStatic.ActionTypes.openWebview,
202            NotificationStatic.ActionTypes.closeNotification
203        ];
204
205        if (validActionTypes.indexOf(button.actionType) === -1) {
206            valid = false;
207        }
208        if (valid === true) {
209            return button;
210        }
211        else {
212
213            return this.handleFallBack(fallBackType, fallBack, "getFinalActionModel", false);
214        }
215    };
216
217    // Return Abort,Ignore,Valid
218    this.validateCondition = function (condition) {
219        var fallBack = this.propNotNull(condition, "fallBack") ? condition.fallBack : null;
220        var fallBackType = condition.fallBackType;
221
222        if (this.propNotNull(condition, "platform")) {
223            if (condition.platform !== NotificationStatic.Platforms.Web) {
224
225                return this.handleFallBack(fallBackType, fallBack, "validateCondition", false);
226            }
227        }
228
229        return "Valid";
230    };
231
232    this.propNotNull = function (model, prop) {
233
234        if (typeof model[prop] !== "undefined" && model[prop] !== null)
235            return true;
236        return false;
237    };
238
239    this.handleFallBack = function (fallBackType, fallBack, fn, topLevel) {
240        if (fallBackType === NotificationStatic.FallBackTypes.FallBack ||
241            fallBackType === NotificationStatic.FallBackTypes.SoftFallBack) {
242            if (fallBack !== null)
243                return this[fn](fallBack);
244            else
245                if (topLevel)
246                    return null;
247                else
248                    return fallBackType === NotificationStatic.FallBackTypes.FallBack ? "Abort" : "Ignore";
249        }
250        else
251            if (topLevel)
252                return null;
253            else
254                return "Ignore";
255    };
256}
257
258var NotificationStatic = {
259    FallBackTypes: {
260        FallBack: 0,
261        SoftFallBack: 1,
262        Iqnore: 2
263    },
264    ActionTypes: {
265        openLink: 0,
266        openIntent: 1,
267        openSelf: 2,
268        closeNotification: 3,
269        openWebview: 4
270    },
271    Platforms: {
272        Android: 0,
273        iOS: 1,
274        Web: 2,
275        WindowsPhone: 3
276    }
277};

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.