37 lines
1.1 KiB
CoffeeScript
37 lines
1.1 KiB
CoffeeScript
Polyfill =
|
|
init: ->
|
|
<% if (type === 'crx') { %>
|
|
@notificationPermission()
|
|
@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: ->
|
|
HTMLCanvasElement::toBlob or= (cb) ->
|
|
data = atob @toDataURL()[22..]
|
|
# DataUrl to Binary code from Aeosynth's 4chan X repo
|
|
l = data.length
|
|
ui8a = new Uint8Array l
|
|
for i in [0...l]
|
|
ui8a[i] = data.charCodeAt i
|
|
cb new Blob [ui8a], type: 'image/png'
|
|
visibility: ->
|
|
# page visibility API
|
|
return unless 'webkitHidden' of document
|
|
Object.defineProperties HTMLDocument.prototype,
|
|
visibilityState:
|
|
get: -> @webkitVisibilityState
|
|
hidden:
|
|
get: -> @webkitHidden
|
|
$.on d, 'webkitvisibilitychange', -> $.event 'visibilitychange'
|