parent
1604c0028a
commit
0a08e7500d
19
lib/$.coffee
19
lib/$.coffee
@ -183,25 +183,8 @@ $.extend $,
|
|||||||
globalEval: (code) ->
|
globalEval: (code) ->
|
||||||
script = $.el 'script',
|
script = $.el 'script',
|
||||||
textContent: code
|
textContent: code
|
||||||
$.add d.head, script
|
$.add (d.head or doc), script
|
||||||
$.rm 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) ->
|
bytesToString: (size) ->
|
||||||
unit = 0 # Bytes
|
unit = 0 # Bytes
|
||||||
while size >= 1024
|
while size >= 1024
|
||||||
|
|||||||
@ -665,33 +665,40 @@ Fourchan =
|
|||||||
|
|
||||||
board = g.BOARD.ID
|
board = g.BOARD.ID
|
||||||
if board is 'g'
|
if board is 'g'
|
||||||
|
$.globalEval """
|
||||||
|
window.addEventListener('prettyprint', function(e) {
|
||||||
|
var pre = e.detail;
|
||||||
|
pre.innerHTML = prettyPrintOne(pre.innerHTML);
|
||||||
|
}, false);
|
||||||
|
"""
|
||||||
Post::callbacks.push
|
Post::callbacks.push
|
||||||
name: 'Parse /g/ code'
|
name: 'Parse /g/ code'
|
||||||
cb: @code
|
cb: @code
|
||||||
if board is 'sci'
|
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
|
Post::callbacks.push
|
||||||
name: 'Parse /sci/ math'
|
name: 'Parse /sci/ math'
|
||||||
cb: @math
|
cb: @math
|
||||||
code: ->
|
code: ->
|
||||||
return if @isClone
|
return if @isClone
|
||||||
for pre in $$ '.prettyprint', @nodes.comment
|
for pre in $$ '.prettyprint', @nodes.comment
|
||||||
pre.innerHTML = $.unsafeWindow.prettyPrintOne pre.innerHTML
|
$.event 'prettyprint', pre, window
|
||||||
return
|
return
|
||||||
math: ->
|
math: ->
|
||||||
return if @isClone or !$ '.math', @nodes.comment
|
return if @isClone or !$ '.math', @nodes.comment
|
||||||
# https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562
|
$.event 'jsmath', @nodes.post, window
|
||||||
{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();
|
|
||||||
"""
|
|
||||||
parseThread: (threadID, offset, limit) ->
|
parseThread: (threadID, offset, limit) ->
|
||||||
# Fix /sci/
|
# Fix /sci/
|
||||||
# Fix /g/
|
# Fix /g/
|
||||||
@ -3523,7 +3530,7 @@ ExpandThread =
|
|||||||
|
|
||||||
# Enable 4chan features.
|
# Enable 4chan features.
|
||||||
if Conf['Enable 4chan\'s Extension']
|
if Conf['Enable 4chan\'s Extension']
|
||||||
$.unsafeWindow.Parser.parseThread thread.ID, 1, nodes.length
|
$.globalEval "Parser.parseThread(#{thread.ID}, 1, #{nodes.length})"
|
||||||
else
|
else
|
||||||
Fourchan.parseThread thread.ID, 1, nodes.length
|
Fourchan.parseThread thread.ID, 1, nodes.length
|
||||||
|
|
||||||
@ -4022,7 +4029,7 @@ ThreadUpdater =
|
|||||||
threadID = ThreadUpdater.thread.ID
|
threadID = ThreadUpdater.thread.ID
|
||||||
{length} = ThreadUpdater.root.children
|
{length} = ThreadUpdater.root.children
|
||||||
if Conf['Enable 4chan\'s Extension']
|
if Conf['Enable 4chan\'s Extension']
|
||||||
$.unsafeWindow.Parser.parseThread threadID, -count
|
$.globalEval "Parser.parseThread(#{threadID}, #{-count})"
|
||||||
else
|
else
|
||||||
Fourchan.parseThread threadID, length - count, length
|
Fourchan.parseThread threadID, length - count, length
|
||||||
|
|
||||||
|
|||||||
@ -577,6 +577,12 @@ QR =
|
|||||||
return unless @isEnabled = !!$.id 'captchaFormPart'
|
return unless @isEnabled = !!$.id 'captchaFormPart'
|
||||||
$.asap (-> $.id 'recaptcha_challenge_field_holder'), @ready.bind @
|
$.asap (-> $.id 'recaptcha_challenge_field_holder'), @ready.bind @
|
||||||
ready: ->
|
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',
|
imgContainer = $.el 'div',
|
||||||
className: 'captcha-img'
|
className: 'captcha-img'
|
||||||
title: 'Reload'
|
title: 'Reload'
|
||||||
@ -644,7 +650,7 @@ QR =
|
|||||||
load: ->
|
load: ->
|
||||||
return unless @nodes.challenge.firstChild
|
return unless @nodes.challenge.firstChild
|
||||||
# -1 minute to give upload some time.
|
# -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
|
challenge = @nodes.challenge.firstChild.value
|
||||||
@nodes.img.alt = challenge
|
@nodes.img.alt = challenge
|
||||||
@nodes.img.src = "//www.google.com/recaptcha/api/image?c=#{challenge}"
|
@nodes.img.src = "//www.google.com/recaptcha/api/image?c=#{challenge}"
|
||||||
@ -662,7 +668,7 @@ QR =
|
|||||||
@nodes.input.alt = count # For XTRM RICE.
|
@nodes.input.alt = count # For XTRM RICE.
|
||||||
reload: (focus) ->
|
reload: (focus) ->
|
||||||
# the 't' argument prevents the input from being focused
|
# the 't' argument prevents the input from being focused
|
||||||
$.unsafeWindow.Recaptcha.reload 't'
|
$.globalEval 'Recaptcha.reload("t")'
|
||||||
# Focus if we meant to.
|
# Focus if we meant to.
|
||||||
@nodes.input.focus() if focus
|
@nodes.input.focus() if focus
|
||||||
keydown: (e) ->
|
keydown: (e) ->
|
||||||
|
|||||||
@ -6,7 +6,7 @@ Report =
|
|||||||
form = $ 'form'
|
form = $ 'form'
|
||||||
field = $.id 'recaptcha_response_field'
|
field = $.id 'recaptcha_response_field'
|
||||||
$.on field, 'keydown', (e) ->
|
$.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) ->
|
$.on form, 'submit', (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
response = field.value.trim()
|
response = field.value.trim()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user