diff --git a/lib/$.coffee b/lib/$.coffee index 1da20735b..6977594ed 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -183,25 +183,8 @@ $.extend $, globalEval: (code) -> script = $.el 'script', textContent: code - $.add d.head, script + $.add (d.head or doc), script $.rm script - # http://mths.be/unsafewindow - unsafeWindow: - if window.opera # Opera - window - else if unsafeWindow? # Firefox - unsafeWindow - else # Chrome - do -> - uw = null - captureUW = (e) -> uw = e.detail - window.addEventListener 'unsafe', captureUW, false - s = d.createElement 'script' - s.textContent = 'window.dispatchEvent(new CustomEvent("unsafe", {detail: window}))' - (d.head or doc).appendChild s - s.parentNode.removeChild s - window.removeEventListener 'unsafe', captureUW, false - uw bytesToString: (size) -> unit = 0 # Bytes while size >= 1024 diff --git a/src/features.coffee b/src/features.coffee index 9675525cf..9eae44902 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -665,33 +665,40 @@ Fourchan = board = g.BOARD.ID if board is 'g' + $.globalEval """ + window.addEventListener('prettyprint', function(e) { + var pre = e.detail; + pre.innerHTML = prettyPrintOne(pre.innerHTML); + }, false); + """ Post::callbacks.push name: 'Parse /g/ code' cb: @code if board is 'sci' + # https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562 + $.globalEval """ + window.addEventListener('jsmath', function(e) { + if (jsMath.loaded) { + // process one post + jsMath.ProcessBeforeShowing(e.detail); + } else { + // load jsMath and process whole document + jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]); + jsMath.Autoload.LoadJsMath(); + } + }, false); + """ Post::callbacks.push name: 'Parse /sci/ math' cb: @math code: -> return if @isClone for pre in $$ '.prettyprint', @nodes.comment - pre.innerHTML = $.unsafeWindow.prettyPrintOne pre.innerHTML + $.event 'prettyprint', pre, window return math: -> return if @isClone or !$ '.math', @nodes.comment - # https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562 - {jsMath} = $.unsafeWindow - if jsMath - if jsMath.loaded - # process one post - jsMath.ProcessBeforeShowing @nodes.post - else - # load jsMath and process whole document - # Yes this requires to be globalEval'd, don't ask me why. - $.globalEval """ - jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]); - jsMath.Autoload.LoadJsMath(); - """ + $.event 'jsmath', @nodes.post, window parseThread: (threadID, offset, limit) -> # Fix /sci/ # Fix /g/ @@ -3523,7 +3530,7 @@ ExpandThread = # Enable 4chan features. if Conf['Enable 4chan\'s Extension'] - $.unsafeWindow.Parser.parseThread thread.ID, 1, nodes.length + $.globalEval "Parser.parseThread(#{thread.ID}, 1, #{nodes.length})" else Fourchan.parseThread thread.ID, 1, nodes.length @@ -4022,7 +4029,7 @@ ThreadUpdater = threadID = ThreadUpdater.thread.ID {length} = ThreadUpdater.root.children if Conf['Enable 4chan\'s Extension'] - $.unsafeWindow.Parser.parseThread threadID, -count + $.globalEval "Parser.parseThread(#{threadID}, #{-count})" else Fourchan.parseThread threadID, length - count, length diff --git a/src/qr.coffee b/src/qr.coffee index 843cc4be2..b52dffe9a 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -577,6 +577,12 @@ QR = return unless @isEnabled = !!$.id 'captchaFormPart' $.asap (-> $.id 'recaptcha_challenge_field_holder'), @ready.bind @ ready: -> + setLifetime = (e) => @lifetime = e.detail + $.on window, 'captcha:timeout', setLifetime + $.globalEval 'window.dispatchEvent(new CustomEvent("captcha:timeout", {detail: RecaptchaState.timeout}))' + $.off window, 'captcha:timeout', setLifetime + c.log @lifetime + imgContainer = $.el 'div', className: 'captcha-img' title: 'Reload' @@ -644,7 +650,7 @@ QR = load: -> return unless @nodes.challenge.firstChild # -1 minute to give upload some time. - @timeout = Date.now() + $.unsafeWindow.RecaptchaState.timeout * $.SECOND - $.MINUTE + @timeout = Date.now() + @lifetime * $.SECOND - $.MINUTE challenge = @nodes.challenge.firstChild.value @nodes.img.alt = challenge @nodes.img.src = "//www.google.com/recaptcha/api/image?c=#{challenge}" @@ -662,7 +668,7 @@ QR = @nodes.input.alt = count # For XTRM RICE. reload: (focus) -> # the 't' argument prevents the input from being focused - $.unsafeWindow.Recaptcha.reload 't' + $.globalEval 'Recaptcha.reload("t")' # Focus if we meant to. @nodes.input.focus() if focus keydown: (e) -> diff --git a/src/report.coffee b/src/report.coffee index 42ae19bd4..eea172ddc 100644 --- a/src/report.coffee +++ b/src/report.coffee @@ -6,7 +6,7 @@ Report = form = $ 'form' field = $.id 'recaptcha_response_field' $.on field, 'keydown', (e) -> - $.unsafeWindow.Recaptcha.reload 't' if e.keyCode is 8 and not field.value + $.globalEval 'Recaptcha.reload("t")' if e.keyCode is 8 and not field.value $.on form, 'submit', (e) -> e.preventDefault() response = field.value.trim()