From 6027d94364fb1f70f9229aafb11d9696d34450e7 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 23 Sep 2018 16:33:03 -0700 Subject: [PATCH] Load Tegaki from rawgit.com if loading from s.4cdn.org fails or is blocked. --- src/Posting/QR.oekaki.coffee | 30 +++++++++++++++++++++++------- src/config/Config.coffee | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Posting/QR.oekaki.coffee b/src/Posting/QR.oekaki.coffee index aff3d5868..5c89589eb 100644 --- a/src/Posting/QR.oekaki.coffee +++ b/src/Posting/QR.oekaki.coffee @@ -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: -> diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 6b07c387b..871a3ded3 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -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'