Merge branch 'v3' of git://github.com/MayhemYDG/4chan-x into v3
Conflicts: css/style.css src/General/Config.coffee src/General/meta/manifest.json src/Posting/QuickReply.coffee
This commit is contained in:
commit
ec32e54ef5
File diff suppressed because one or more lines are too long
@ -15,7 +15,7 @@
|
||||
"run_at": "document_start"
|
||||
}],
|
||||
"homepage_url": "http://seaweedchan.github.io/4chan-x/",
|
||||
"minimum_chrome_version": "26",
|
||||
"minimum_chrome_version": "27",
|
||||
"permissions": [
|
||||
"storage"
|
||||
]
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -17,6 +17,10 @@ Config =
|
||||
true
|
||||
'Add button to hide 4chan announcements.'
|
||||
]
|
||||
'Desktop Notifications': [
|
||||
true
|
||||
'Enables desktop notifications across various <%= meta.name %> features.'
|
||||
]
|
||||
'404 Redirect': [
|
||||
true
|
||||
'Redirect dead threads and images.'
|
||||
|
||||
@ -91,6 +91,8 @@ Header =
|
||||
Header.setFooterVisibility Conf['Bottom Board List']
|
||||
$.sync 'Bottom Board List', Header.setFooterVisibility
|
||||
|
||||
@enableDesktopNotifications()
|
||||
|
||||
bar: $.el 'div',
|
||||
id: 'header-bar'
|
||||
|
||||
@ -276,7 +278,7 @@ Header =
|
||||
'The bottom navigation will now be hidden.'
|
||||
else
|
||||
'The bottom navigation will remain visible.'
|
||||
new Notification 'info', message, 2
|
||||
new Notice 'info', message, 2
|
||||
|
||||
setCustomNav: (show) ->
|
||||
Header.customNavToggler.checked = show
|
||||
@ -322,3 +324,31 @@ Header =
|
||||
{type, content, lifetime, cb} = e.detail
|
||||
notif = new Notice type, content, lifetime
|
||||
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
|
||||
|
||||
@ -3,4 +3,4 @@
|
||||
<%= grunt.file.read('src/General/lib/post.class') %>
|
||||
<%= grunt.file.read('src/General/lib/clone.class') %>
|
||||
<%= grunt.file.read('src/General/lib/databoard.class') %>
|
||||
<%= grunt.file.read('src/General/lib/notification.class') %>
|
||||
<%= grunt.file.read('src/General/lib/notice.class') %>
|
||||
@ -1,28 +0,0 @@
|
||||
class Notification
|
||||
constructor: (type, content, @timeout) ->
|
||||
@el = $.el 'div',
|
||||
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
||||
@el.style.opacity = 0
|
||||
@setType type
|
||||
$.on @el.firstElementChild, 'click', @close
|
||||
if typeof content is 'string'
|
||||
content = $.tn content
|
||||
$.add @el.lastElementChild, content
|
||||
|
||||
$.ready @add
|
||||
|
||||
setType: (type) ->
|
||||
@el.className = "notification #{type}"
|
||||
|
||||
add: =>
|
||||
if d.hidden
|
||||
$.on d, 'visibilitychange', @add
|
||||
return
|
||||
$.off d, 'visibilitychange', @add
|
||||
$.add $.id('notifications'), @el
|
||||
@el.clientHeight # force reflow
|
||||
@el.style.opacity = 1
|
||||
setTimeout @close, @timeout * $.SECOND if @timeout
|
||||
|
||||
close: =>
|
||||
$.rm @el
|
||||
@ -1,9 +1,21 @@
|
||||
Polyfill =
|
||||
init: ->
|
||||
<% if (type === 'crx') { %>
|
||||
Polyfill.toBlob()
|
||||
Polyfill.visibility()
|
||||
@notificationPermission()
|
||||
@toBlob()
|
||||
@visibility()
|
||||
<% } %>
|
||||
notificationPermission: ->
|
||||
return if !window.Notification or 'permission' of Notification
|
||||
Object.defineProperty Notification, 'permission',
|
||||
get: ->
|
||||
switch webkitNotifications.checkPermission()
|
||||
when 0
|
||||
'granted'
|
||||
when 1
|
||||
'default'
|
||||
when 2
|
||||
'denied'
|
||||
toBlob: ->
|
||||
HTMLCanvasElement::toBlob or= (cb) ->
|
||||
data = atob @toDataURL()[22..]
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
"run_at": "document_start"
|
||||
}],
|
||||
"homepage_url": "<%= meta.page %>",
|
||||
"minimum_chrome_version": "26",
|
||||
"minimum_chrome_version": "27",
|
||||
"permissions": [
|
||||
"storage"
|
||||
]
|
||||
|
||||
@ -22,7 +22,7 @@ ImageExpand =
|
||||
ImageExpand.contract @
|
||||
ImageExpand.expand @
|
||||
return
|
||||
if ImageExpand.on and !@isHidden
|
||||
if ImageExpand.on and !@isHidden and (Conf['Expand spoilers'] or !@file.isSpoiler)
|
||||
ImageExpand.expand @
|
||||
cb:
|
||||
toggle: (e) ->
|
||||
|
||||
@ -95,12 +95,12 @@ Unread =
|
||||
Unread.openNotification post
|
||||
return
|
||||
openNotification: (post) ->
|
||||
return unless d.hidden
|
||||
return unless Header.areNotificationsEnabled
|
||||
name = if Conf['Anonymize']
|
||||
'Anonymous'
|
||||
else
|
||||
$('.nameBlock', post.nodes.info).textContent.trim()
|
||||
notif = new Notification "#{name} replied to you.",
|
||||
notif = new Notice "#{name} replied to you",
|
||||
body: post.info.comment
|
||||
icon: Favicon.logo
|
||||
notif.onclick = ->
|
||||
|
||||
@ -153,16 +153,20 @@ QR =
|
||||
notify: (el) ->
|
||||
notice = new Notice 'warning', el
|
||||
QR.notifications.push notice
|
||||
return unless d.hidden
|
||||
notif = new Notification 'Quick reply warning',
|
||||
return unless Header.areNotificationsEnabled
|
||||
notif = new Notice 'Quick reply warning',
|
||||
body: el.textContent
|
||||
icon: Favicon.logo
|
||||
notif.onclick = -> window.focus()
|
||||
<% if (type === 'crx') { %>
|
||||
# Firefox automatically closes notifications
|
||||
# so we can't control the onclose properly.
|
||||
notif.onclose = -> notice.close()
|
||||
setTimeout ->
|
||||
notif.onclose = null
|
||||
notif.close()
|
||||
, 5 * $.SECOND
|
||||
<% } %>
|
||||
|
||||
notifications: []
|
||||
cleanNotifications: ->
|
||||
@ -1180,7 +1184,7 @@ QR =
|
||||
QR.cleanNotifications()
|
||||
|
||||
if Conf['Posting Success Notifications']
|
||||
QR.notifications.push new Notification 'success', h1.textContent, 5
|
||||
QR.notifications.push new Notice 'success', h1.textContent, 5
|
||||
|
||||
QR.persona.set post
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ QuoteYou =
|
||||
|
||||
unless QuoteYou.lastRead
|
||||
unless post = QuoteYou.lastRead = $ '.quotesYou'
|
||||
new Notification 'warning', 'No posts are currently quoting you, loser.', 20
|
||||
new Notice 'warning', 'No posts are currently quoting you, loser.', 20
|
||||
return
|
||||
return if QuoteYou.cb.scroll post
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user