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:
Zixaphir 2013-08-17 21:00:31 -07:00
commit ec32e54ef5
14 changed files with 207 additions and 175 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@
"run_at": "document_start" "run_at": "document_start"
}], }],
"homepage_url": "http://seaweedchan.github.io/4chan-x/", "homepage_url": "http://seaweedchan.github.io/4chan-x/",
"minimum_chrome_version": "26", "minimum_chrome_version": "27",
"permissions": [ "permissions": [
"storage" "storage"
] ]

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,10 @@ Config =
true true
'Add button to hide 4chan announcements.' 'Add button to hide 4chan announcements.'
] ]
'Desktop Notifications': [
true
'Enables desktop notifications across various <%= meta.name %> features.'
]
'404 Redirect': [ '404 Redirect': [
true true
'Redirect dead threads and images.' 'Redirect dead threads and images.'

View File

@ -91,6 +91,8 @@ Header =
Header.setFooterVisibility Conf['Bottom Board List'] Header.setFooterVisibility Conf['Bottom Board List']
$.sync 'Bottom Board List', Header.setFooterVisibility $.sync 'Bottom Board List', Header.setFooterVisibility
@enableDesktopNotifications()
bar: $.el 'div', bar: $.el 'div',
id: 'header-bar' id: 'header-bar'
@ -276,7 +278,7 @@ Header =
'The bottom navigation will now be hidden.' 'The bottom navigation will now be hidden.'
else else
'The bottom navigation will remain visible.' 'The bottom navigation will remain visible.'
new Notification 'info', message, 2 new Notice 'info', message, 2
setCustomNav: (show) -> setCustomNav: (show) ->
Header.customNavToggler.checked = show Header.customNavToggler.checked = show
@ -322,3 +324,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

View File

@ -3,4 +3,4 @@
<%= grunt.file.read('src/General/lib/post.class') %> <%= grunt.file.read('src/General/lib/post.class') %>
<%= grunt.file.read('src/General/lib/clone.class') %> <%= grunt.file.read('src/General/lib/clone.class') %>
<%= grunt.file.read('src/General/lib/databoard.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') %>

View File

@ -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

View File

@ -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 or '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..]

View File

@ -15,7 +15,7 @@
"run_at": "document_start" "run_at": "document_start"
}], }],
"homepage_url": "<%= meta.page %>", "homepage_url": "<%= meta.page %>",
"minimum_chrome_version": "26", "minimum_chrome_version": "27",
"permissions": [ "permissions": [
"storage" "storage"
] ]

View File

@ -22,7 +22,7 @@ ImageExpand =
ImageExpand.contract @ ImageExpand.contract @
ImageExpand.expand @ ImageExpand.expand @
return return
if ImageExpand.on and !@isHidden if ImageExpand.on and !@isHidden and (Conf['Expand spoilers'] or !@file.isSpoiler)
ImageExpand.expand @ ImageExpand.expand @
cb: cb:
toggle: (e) -> toggle: (e) ->

View File

@ -95,12 +95,12 @@ Unread =
Unread.openNotification post Unread.openNotification post
return return
openNotification: (post) -> openNotification: (post) ->
return unless d.hidden return unless 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 Notice "#{name} replied to you",
body: post.info.comment body: post.info.comment
icon: Favicon.logo icon: Favicon.logo
notif.onclick = -> notif.onclick = ->

View File

@ -153,16 +153,20 @@ QR =
notify: (el) -> notify: (el) ->
notice = new Notice 'warning', el notice = new Notice 'warning', el
QR.notifications.push notice QR.notifications.push notice
return unless d.hidden return unless Header.areNotificationsEnabled
notif = new Notification 'Quick reply warning', notif = new Notice 'Quick reply warning',
body: el.textContent body: el.textContent
icon: Favicon.logo icon: Favicon.logo
notif.onclick = -> window.focus() notif.onclick = -> window.focus()
<% if (type === 'crx') { %>
# Firefox automatically closes notifications
# so we can't control the onclose properly.
notif.onclose = -> notice.close() notif.onclose = -> notice.close()
setTimeout -> setTimeout ->
notif.onclose = null notif.onclose = null
notif.close() notif.close()
, 5 * $.SECOND , 5 * $.SECOND
<% } %>
notifications: [] notifications: []
cleanNotifications: -> cleanNotifications: ->
@ -1180,7 +1184,7 @@ QR =
QR.cleanNotifications() QR.cleanNotifications()
if Conf['Posting Success Notifications'] 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 QR.persona.set post

View File

@ -36,7 +36,7 @@ QuoteYou =
unless QuoteYou.lastRead unless QuoteYou.lastRead
unless post = QuoteYou.lastRead = $ '.quotesYou' 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
return if QuoteYou.cb.scroll post return if QuoteYou.cb.scroll post
else else