pushilka 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +1 -1
- package/dist/serviceWorker.js +1 -1
- package/gulpfile.js +18 -25
- package/package.json +7 -5
- package/src/app.js +32 -2
- package/src/.DS_Store +0 -0
package/dist/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function Pushilka(e){var n,
|
|
1
|
+
function Pushilka(e){var n,t,o=u(),i={endpoint:"https://swarmpush.com/push_subscription.php",eventEndpoint:"https://swarmpush.com/event",serviceWorker:"/serviceWorker.js",serviceWorkerOptions:{scope:"/"},applicationServerKey:"BCmIwkLHxJNPccoVf2UXDjd7kDuiyJpKsSOqSHCtGBMfBkjfHLCq4-d8eNtabNlCNKFF8CZIzeDwOo3OvNCQAns",source:"",var1:"",var2:"",var3:"",var4:"",var5:"",var6:"",var7:"",var8:"",var9:"",var10:"",useDialog:!1,visitorCookie:"pushilka_vid",dialog:{ttl:30,message:"We'd like to send you notifications for the latest news and updates.",allowText:"Allow",cancelText:"No thanks",icon:"https://swarmpush.com/s/pushilka/bell.webp",style:"https://swarmpush.com/s/pushilka/app.css",template:'<div id="pushilka-dialog" class="pushilka-dialog"><div class="pushilka-icon"><img width="80" src="{ICON_URL}" alt=""></div><div class="pushilka-message">{MESSAGE}</div><div class="pushilka-buttons"><a href="" id="pushilka-agree-button" class="pushilka-agree-button">{ALLOW_TEXT}</a><a href="" id="pushilka-cancel-button" class="pushilka-cancel-button">{CANCEL_TEXT}</a></div></div>'},done:function(){},success:function(){},decline:function(){}};for(t in e)if(e.hasOwnProperty(t)&&"dialog"===t)for(var r in e[t])e[t].hasOwnProperty(r)&&i[t].hasOwnProperty(r)&&(i[t][r]=e[t][r]);else e.hasOwnProperty(t)&&i.hasOwnProperty(t)&&(i[t]=e[t]);function a(e){fetch(i.eventEndpoint,{method:"POST",body:JSON.stringify({event:e,source:i.source,visitorId:l(),sessionId:o,var1:i.var1,var2:i.var2,var3:i.var3,var4:i.var4,var5:i.var5,var6:i.var6,var7:i.var7,var8:i.var8,var9:i.var9,var10:i.var10})}).catch()}function s(e,n,t){var o=new Date;o.setTime(o.getTime()+60*t*1e3),t="; expires="+o.toUTCString(),document.cookie=e+"="+(n||"")+t+"; path=/"}function c(e){var n,t=document.cookie.split(";"),o=e+"=";for(n in t){var r=t[n].trimLeft();if(0===r.indexOf(o))return r.substring(o.length)}return null}function d(){navigator.serviceWorker.ready.then(function(e){return a("sys_push_invoked"),e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){for(var e=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=window.atob(e),t=new Uint8Array(n.length),o=0;o<n.length;++o)t[o]=n.charCodeAt(o);return t}(i.applicationServerKey)})}).then(function(e){return v(e,"POST")}).catch(function(){a("sys_push_blocked"),i.decline(),i.done()})}function u(){for(var e=[],n=0;n<2;n++)e.push(Math.floor(4294967295*Math.random()).toString(36));return e.join("-")}function l(){var e=window.localStorage;return n=n||e.getItem("visitorId")||c(i.visitorCookie)||u(),e.setItem("visitorId",n),s(i.visitorCookie,n,365),n}function p(e){return e+"?vid="+encodeURIComponent(l())+"&sid="+encodeURIComponent(o)+"&s="+encodeURIComponent(i.source.toString())+"&var1="+encodeURIComponent(i.var1.toString())+"&var2="+encodeURIComponent(i.var2.toString())+"&var3="+encodeURIComponent(i.var3.toString())+"&var4="+encodeURIComponent(i.var4.toString())+"&var5="+encodeURIComponent(i.var5.toString())+"&var6="+encodeURIComponent(i.var6.toString())+"&var7="+encodeURIComponent(i.var7.toString())+"&var8="+encodeURIComponent(i.var8.toString())+"&var9="+encodeURIComponent(i.var9.toString())+"&var10="+encodeURIComponent(i.var10.toString())+"&timezone="+encodeURIComponent(function(){let e="";try{e=Intl.DateTimeFormat().resolvedOptions().timeZone}catch(e){console.error(e)}return e}())}function v(e,n){var t=e.getKey("p256dh"),o=e.getKey("auth"),r=(PushManager.supportedContentEncodings||["aesgcm"])[0];return fetch(p(i.endpoint),{method:n,body:JSON.stringify({endpoint:e.endpoint,publicKey:t?btoa(String.fromCharCode.apply(null,new Uint8Array(t))):null,authToken:o?btoa(String.fromCharCode.apply(null,new Uint8Array(o))):null,contentEncoding:r})}).then(function(){return i.success(),i.done(),e}).catch(function(){i.success(),i.done()})}this.ready=function(e){"interactive"===document.readyState||"complete"===document.readyState?e():document.addEventListener("DOMContentLoaded",e)},this.run=function(){this.ready(function(){"showNotification"in ServiceWorkerRegistration.prototype==!1?(console.debug("Push messaging is not supported."),a("push_not_supported"),i.decline(),i.done()):"denied"===Notification.permission?(console.debug("User has blocked notifications."),a("sys_push_blocked"),i.decline(),i.done()):navigator.serviceWorker.register(i.serviceWorker,i.serviceWorkerOptions).then(function(){navigator.serviceWorker.ready.then(function(e){return e.pushManager.getSubscription()}).then(function(e){return e?v(e,"PUT"):i.useDialog?void(null!==c("pushilka-dialog")?a("push_blocked"):(a("push_invoked"),e=i.dialog,(n=document.createElement("link")).rel="stylesheet",n.href=e.style,document.body.appendChild(n),(n=document.createElement("div")).innerHTML=e.template.replace("{ICON_URL}",e.icon).replace("{MESSAGE}",e.message).replace("{ALLOW_TEXT}",e.allowText).replace("{CANCEL_TEXT}",e.cancelText),document.body.appendChild(n),(t={agreeButton:document.getElementById("pushilka-agree-button"),cancelButton:document.getElementById("pushilka-cancel-button"),dialog:document.getElementById("pushilka-dialog")}).agreeButton.addEventListener("click",function(e){e.preventDefault(),t.dialog.remove(),d()}),t.cancelButton.addEventListener("click",function(e){e.preventDefault(),a("push_blocked"),s("pushilka-dialog","1",i.dialog.ttl),t.dialog.remove()}))):d();var n,t})}).catch(function(){a("sys_push_subscribe_error"),i.decline(),i.done()})})}}
|
package/dist/serviceWorker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
self.addEventListener("push",function(i){
|
|
1
|
+
self.addEventListener("push",function(i){var t;self.Notification&&"granted"===self.Notification.permission&&i.data&&(t=i.data.json(),i.waitUntil((i=t,self.registration.showNotification(i.title,{body:i.body,icon:i.icon,badge:i.badge,image:i.image,vibrate:i.vibrate,sound:i.sound,sticky:!0,noscreen:!1,requireInteraction:!1,timestamp:i.timestamp,data:{url:i.url,msg_id:i.hasOwnProperty("msg_id")?i.msg_id:""}}))))}),self.addEventListener("notificationclick",function(i){i.notification.close(),i.waitUntil(clients.openWindow(i.notification.data.url))});
|
package/gulpfile.js
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
pump = require('pump');
|
|
1
|
+
const {series, src, dest} = require('gulp');
|
|
2
|
+
const uglify = require('gulp-uglify');
|
|
3
|
+
const uglifycss = require('gulp-uglifycss');
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
]);
|
|
12
|
-
});
|
|
5
|
+
function scripts() {
|
|
6
|
+
return src('src/*.js')
|
|
7
|
+
.pipe(uglify())
|
|
8
|
+
.pipe(dest('dist/'));
|
|
9
|
+
}
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
11
|
+
function css() {
|
|
12
|
+
return src('src/*.css')
|
|
13
|
+
.pipe(uglifycss())
|
|
14
|
+
.pipe(dest('dist/'))
|
|
15
|
+
}
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]);
|
|
27
|
-
});
|
|
17
|
+
function images() {
|
|
18
|
+
return src('src/*.{webp,jpg,png,gif}')
|
|
19
|
+
.pipe(dest('dist/'));
|
|
20
|
+
}
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
exports.default = series(scripts, css, images)
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pushilka",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Web push client",
|
|
5
5
|
"main": "./dist/app.js",
|
|
6
|
-
"dependencies": {},
|
|
7
6
|
"devDependencies": {
|
|
8
7
|
"gulp": "^4.0.2",
|
|
9
|
-
"gulp-uglify": "^3.0.
|
|
10
|
-
"gulp-uglifycss": "^1.1.0"
|
|
11
|
-
"pump": "^3.0.0"
|
|
8
|
+
"gulp-uglify": "^3.0.2",
|
|
9
|
+
"gulp-uglifycss": "^1.1.0"
|
|
12
10
|
},
|
|
13
11
|
"scripts": {
|
|
14
12
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -22,5 +20,9 @@
|
|
|
22
20
|
"bugs": {
|
|
23
21
|
"url": "https://github.com/pushilka/pushilka/issues"
|
|
24
22
|
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"npm": ">=9.0.0 <10.0.0",
|
|
25
|
+
"node": ">=18.0.0 <19.0.0"
|
|
26
|
+
},
|
|
25
27
|
"homepage": "https://github.com/pushilka/pushilka#readme"
|
|
26
28
|
}
|
package/src/app.js
CHANGED
|
@@ -13,6 +13,12 @@ function Pushilka(options) {
|
|
|
13
13
|
var2: "",
|
|
14
14
|
var3: "",
|
|
15
15
|
var4: "",
|
|
16
|
+
var5: "",
|
|
17
|
+
var6: "",
|
|
18
|
+
var7: "",
|
|
19
|
+
var8: "",
|
|
20
|
+
var9: "",
|
|
21
|
+
var10: "",
|
|
16
22
|
useDialog: false,
|
|
17
23
|
visitorCookie: 'pushilka_vid',
|
|
18
24
|
dialog: {
|
|
@@ -73,7 +79,13 @@ function Pushilka(options) {
|
|
|
73
79
|
var1: params.var1,
|
|
74
80
|
var2: params.var2,
|
|
75
81
|
var3: params.var3,
|
|
76
|
-
var4: params.var4
|
|
82
|
+
var4: params.var4,
|
|
83
|
+
var5: params.var5,
|
|
84
|
+
var6: params.var6,
|
|
85
|
+
var7: params.var7,
|
|
86
|
+
var8: params.var8,
|
|
87
|
+
var9: params.var9,
|
|
88
|
+
var10: params.var10,
|
|
77
89
|
})
|
|
78
90
|
}).catch();
|
|
79
91
|
}
|
|
@@ -179,6 +191,17 @@ function Pushilka(options) {
|
|
|
179
191
|
return visitorId;
|
|
180
192
|
}
|
|
181
193
|
|
|
194
|
+
function getTimezone() {
|
|
195
|
+
let timezone = "";
|
|
196
|
+
try {
|
|
197
|
+
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error(error);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return timezone;
|
|
203
|
+
}
|
|
204
|
+
|
|
182
205
|
function getEndpoint(endpoint) {
|
|
183
206
|
return endpoint + '?'
|
|
184
207
|
+ 'vid=' + encodeURIComponent(getVisitorId())
|
|
@@ -187,7 +210,14 @@ function Pushilka(options) {
|
|
|
187
210
|
+ '&var1=' + encodeURIComponent(params.var1.toString())
|
|
188
211
|
+ '&var2=' + encodeURIComponent(params.var2.toString())
|
|
189
212
|
+ '&var3=' + encodeURIComponent(params.var3.toString())
|
|
190
|
-
+ '&var4=' + encodeURIComponent(params.var4.toString())
|
|
213
|
+
+ '&var4=' + encodeURIComponent(params.var4.toString())
|
|
214
|
+
+ '&var5=' + encodeURIComponent(params.var5.toString())
|
|
215
|
+
+ '&var6=' + encodeURIComponent(params.var6.toString())
|
|
216
|
+
+ '&var7=' + encodeURIComponent(params.var7.toString())
|
|
217
|
+
+ '&var8=' + encodeURIComponent(params.var8.toString())
|
|
218
|
+
+ '&var9=' + encodeURIComponent(params.var9.toString())
|
|
219
|
+
+ '&var10=' + encodeURIComponent(params.var10.toString())
|
|
220
|
+
+ '&timezone=' + encodeURIComponent(getTimezone());
|
|
191
221
|
}
|
|
192
222
|
|
|
193
223
|
function sendSubscriptionToServer(subscription, method) {
|
package/src/.DS_Store
DELETED
|
Binary file
|