Add desktop notification permission granting setting and notice.
This commit is contained in:
parent
43fbf62da0
commit
5742405f67
@ -1,9 +1,21 @@
|
|||||||
Polyfill =
|
Polyfill =
|
||||||
init: ->
|
init: ->
|
||||||
<% if (type === 'crx') { %>
|
<% if (type === 'crx') { %>
|
||||||
Polyfill.toBlob()
|
@notificationPermission()
|
||||||
Polyfill.visibility()
|
@toBlob()
|
||||||
|
@visibility()
|
||||||
<% } %>
|
<% } %>
|
||||||
|
notificationPermission: ->
|
||||||
|
return if window.Notification and 'permission' of Notification
|
||||||
|
Object.defineProperty Notification, 'permission',
|
||||||
|
get: ->
|
||||||
|
switch webkitNotifications.checkPermission()
|
||||||
|
when 0
|
||||||
|
'granted'
|
||||||
|
when 1
|
||||||
|
'default'
|
||||||
|
when 2
|
||||||
|
'denied'
|
||||||
toBlob: ->
|
toBlob: ->
|
||||||
HTMLCanvasElement::toBlob or= (cb) ->
|
HTMLCanvasElement::toBlob or= (cb) ->
|
||||||
data = atob @toDataURL()[22..]
|
data = atob @toDataURL()[22..]
|
||||||
|
|||||||
@ -2,6 +2,7 @@ Config =
|
|||||||
main:
|
main:
|
||||||
'Miscellaneous':
|
'Miscellaneous':
|
||||||
'Enable 4chan\'s Extension': [false, 'Compatibility between <%= meta.name %> and 4chan\'s inline extension is NOT guaranteed.']
|
'Enable 4chan\'s Extension': [false, 'Compatibility between <%= meta.name %> and 4chan\'s inline extension is NOT guaranteed.']
|
||||||
|
'Desktop Notifications': [true, 'Enables desktop notifications across various <%= meta.name %> features.']
|
||||||
'Announcement Hiding': [true, 'Add button to hide 4chan announcements.']
|
'Announcement Hiding': [true, 'Add button to hide 4chan announcements.']
|
||||||
'404 Redirect': [true, 'Redirect dead threads and images.']
|
'404 Redirect': [true, 'Redirect dead threads and images.']
|
||||||
'Keybinds': [true, 'Bind actions to keyboard shortcuts.']
|
'Keybinds': [true, 'Bind actions to keyboard shortcuts.']
|
||||||
|
|||||||
@ -89,6 +89,8 @@ Header =
|
|||||||
Header.setCatalogLinks Conf['Header catalog links']
|
Header.setCatalogLinks Conf['Header catalog links']
|
||||||
$.sync 'Header catalog links', Header.setCatalogLinks
|
$.sync 'Header catalog links', Header.setCatalogLinks
|
||||||
|
|
||||||
|
@enableDesktopNotifications()
|
||||||
|
|
||||||
setBoardList: ->
|
setBoardList: ->
|
||||||
nav = $.id 'boardNavDesktop'
|
nav = $.id 'boardNavDesktop'
|
||||||
if a = $ "a[href*='/#{g.BOARD}/']", nav
|
if a = $ "a[href*='/#{g.BOARD}/']", nav
|
||||||
@ -268,3 +270,31 @@ Header =
|
|||||||
{type, content, lifetime, cb} = e.detail
|
{type, content, lifetime, cb} = e.detail
|
||||||
notif = new Notice type, content, lifetime
|
notif = new Notice type, content, lifetime
|
||||||
cb notif if cb
|
cb notif if cb
|
||||||
|
|
||||||
|
areNotificationsEnabled: false
|
||||||
|
enableDesktopNotifications: ->
|
||||||
|
return unless window.Notification and Conf['Desktop Notifications']
|
||||||
|
switch Notification.permission
|
||||||
|
when 'granted'
|
||||||
|
Header.areNotificationsEnabled = true
|
||||||
|
return
|
||||||
|
when 'denied'
|
||||||
|
# requestPermission doesn't work if status is 'denied',
|
||||||
|
# but it'll still work if status is 'default'.
|
||||||
|
return
|
||||||
|
|
||||||
|
el = $.el 'span',
|
||||||
|
innerHTML: """
|
||||||
|
Desktop notification permissions are not granted:<br>
|
||||||
|
<button>Authorize</button> or <button>Disable</button>
|
||||||
|
"""
|
||||||
|
[authorize, disable] = $$ 'button', el
|
||||||
|
$.on authorize, 'click', ->
|
||||||
|
Notification.requestPermission (status) ->
|
||||||
|
Header.areNotificationsEnabled = status is 'granted'
|
||||||
|
return if status is 'default'
|
||||||
|
notice.close()
|
||||||
|
$.on disable, 'click', ->
|
||||||
|
$.set 'Desktop Notifications', false
|
||||||
|
notice.close()
|
||||||
|
notice = new Notice 'info', el
|
||||||
|
|||||||
@ -96,12 +96,12 @@ Unread =
|
|||||||
Unread.openNotification post
|
Unread.openNotification post
|
||||||
return
|
return
|
||||||
openNotification: (post) ->
|
openNotification: (post) ->
|
||||||
return unless d.hidden
|
return unless d.hidden and Header.areNotificationsEnabled
|
||||||
name = if Conf['Anonymize']
|
name = if Conf['Anonymize']
|
||||||
'Anonymous'
|
'Anonymous'
|
||||||
else
|
else
|
||||||
$('.nameBlock', post.nodes.info).textContent.trim()
|
$('.nameBlock', post.nodes.info).textContent.trim()
|
||||||
notif = new Notification "#{name} replied to you.",
|
notif = new Notification "#{name} replied to you",
|
||||||
body: post.info.comment
|
body: post.info.comment
|
||||||
icon: Favicon.logo
|
icon: Favicon.logo
|
||||||
notif.onclick = ->
|
notif.onclick = ->
|
||||||
|
|||||||
@ -113,7 +113,7 @@ QR =
|
|||||||
QR.captcha.nodes.input.focus()
|
QR.captcha.nodes.input.focus()
|
||||||
notice = new Notice 'warning', el
|
notice = new Notice 'warning', el
|
||||||
QR.notifications.push notice
|
QR.notifications.push notice
|
||||||
return unless d.hidden
|
return unless d.hidden and Header.areNotificationsEnabled
|
||||||
notif = new Notification 'Quick reply warning',
|
notif = new Notification 'Quick reply warning',
|
||||||
body: el.textContent
|
body: el.textContent
|
||||||
icon: Favicon.logo
|
icon: Favicon.logo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user