Load Tegaki from rawgit.com if loading from s.4cdn.org fails or is blocked.

This commit is contained in:
ccd0 2018-09-23 16:33:03 -07:00
parent ee44aa356e
commit 6027d94364
2 changed files with 24 additions and 7 deletions

View File

@ -55,23 +55,39 @@ QR.oekaki =
bubbles: true
detail: {file, name: FCX.oekakiName, source}
}
if window.Tegaki
document.querySelector('#qr .oekaki').hidden = false
if $ 'link[href^="//s.4cdn.org/css/painter"]', d.head
QR.oekaki.load ->
$('#qr .oekaki').hidden = false
load: (cb) ->
if $ 'script[src^="//s.4cdn.org/js/painter"]', d.head
cb()
n = 0
onload = ->
cb() if ++n is 2
onerror = ->
$.rm @
script = $.el 'script',
src: 'https://rawgit.com/desuwa/tegaki/master/tegaki.js'
$.on script, 'load', onload
$.add d.head, script
script = $ 'script[src^="//s.4cdn.org/js/painter"], script[src="https://rawgit.com/desuwa/tegaki/master/tegaki.js"]', d.head
if script
if !script.dataset.success
$.global ->
document.querySelector('script[src^="//s.4cdn.org/js/painter"], script[src="https://rawgit.com/desuwa/tegaki/master/tegaki.js"]').dataset.success = !!window.Tegaki
if script.dataset.success is 'true'
cb()
else
n = 1
onerror.call script
else
style = $.el 'link',
rel: 'stylesheet'
href: "//s.4cdn.org/css/painter.#{Date.now()}.css"
script = $.el 'script',
src: "//s.4cdn.org/js/painter.min.#{Date.now()}.js"
n = 0
onload = ->
cb() if ++n is 2
$.on style, 'load', onload
$.on script, 'load', onload
$.on script, 'error', onerror
$.add d.head, [style, script]
draw: ->

View File

@ -832,6 +832,7 @@ Config =
http://cdn.mathjax.org
https://cdn.mathjax.org
https://cdnjs.cloudflare.com
https://rawgit.com
'self'
'unsafe-inline'
'unsafe-eval'