Skip to content

Instantly share code, notes, and snippets.

View vldvel's full-sized avatar

Vlad vldvel

  • Amsterdam
View GitHub Profile
@vldvel
vldvel / Notification-onclick.js
Created March 14, 2018 14:39
Notification onclick
function notifyClicked = () => {
console.log('notify has been clicked');
}
Notification.onclick = notifyClicked; // won't work
Notification.prototype.onclick = notifyClicked; // won't work
const notification = Notification('Notificated!');
notification.__proto__.onclick = notifyClicked; // won't work
@vldvel
vldvel / Notification-properties.js
Created March 14, 2018 13:28
Notification properties
const notificationProps = {
title: 'I\'m notification',
body: 'Here is my desription',
icon: 'https://avatars1.githubusercontent.com/u/22643415',
vibrate: [50, 100, 150]
}
const myNotification = new Notification(notificationProps.title, notificationProps);
console.log(myNotification.title); // 'I\'m notification'
@vldvel
vldvel / Notification-permission.js
Created March 14, 2018 13:18
Notification permission
switch (Notification.permission) {
case 'granted': {
new Notification('Hello world!');
break;
}
case 'denied': {
alert('No notification for you!');
break;
}
case 'default': {
@vldvel
vldvel / Notification-close.js
Created March 14, 2018 12:40
Notification close
const notificationProps = {
title: 'I\'m notification',
body: 'Here is my desription',
icon: 'https://avatars1.githubusercontent.com/u/22643415',
vibrate: [50, 100, 150]
}
const myNotification = new Notification(notificationProps.title, notificationProps);
function closeNotification(notifyID, time) {
@vldvel
vldvel / Notification-options.js
Last active March 15, 2018 12:09
Notification with options
const notificationTitle = 'I\'m notification'; // string
const notificationOptions = {
tag: 'notification', // tag for notification
renotify: true, // defalt false, renotifying after old notification
body: 'Here is my desription', // description under title
icon: 'https://avatars1.githubusercontent.com/u/22643415', // image URL
vibrate: [50, 100, 150] // vibration on notification
}
@vldvel
vldvel / Notification-simple.js
Last active March 15, 2018 07:21
Notification simple
const title = 'I\'m notification!';
notification(title); // wrong - notification is not defined
Notification(title); // wrong - Failed to construct Notification
new Notification(title); // OK
const notification = new Notification(title); // OK
@vldvel
vldvel / Notification-request-promise.js
Created March 14, 2018 07:51
Notification request promise
Notification
.requestPermission()
.then((permission) => {
if (permission !== 'granted') throw new Error('No access!');
})
.then(() => {
console.log('We have an access!');
// Handle granted permission here
})
.catch((err) => {
@vldvel
vldvel / Notification-check.js
Created March 14, 2018 07:27
Notification check
if (!('Notification' in window)) {
// Place notification logic here
}
@vldvel
vldvel / Notification-request.js
Last active April 14, 2018 02:21
Notification Request API
Notification.requestPermission((permission) => {
switch (permission) {
case 'granted': {
console.log('Now we can send notifications!');
break;
}
case 'denied': {
console.log('User close the request pop-up!')
}
case 'default': {
function * generator() {
yield 1;
}
generator.prototype.__proto__; // Generator {constructor: GeneratorFunction, next: ƒ, return: ƒ, throw: ƒ, Symbol(Symbol.toStringTag): "Generator"}
// as Generator is not global variable we have to write something like this
generator.prototype.__proto__.math = function(e = 0) {
return e * Math.PI;
}