formatting
This commit is contained in:
parent
52b6d7982f
commit
04d56c0b3f
123
4chan_x.coffee
123
4chan_x.coffee
@ -122,17 +122,17 @@ AEOS =
|
|||||||
d = document
|
d = document
|
||||||
$ = (selector, root) ->
|
$ = (selector, root) ->
|
||||||
root or= d.body
|
root or= d.body
|
||||||
root.querySelector(selector)
|
root.querySelector selector
|
||||||
$$ = (selector, root) ->
|
$$ = (selector, root) ->
|
||||||
root or= d.body
|
root or= d.body
|
||||||
result = root.querySelectorAll(selector)
|
result = root.querySelectorAll selector
|
||||||
#magic that turns the results object into an array:
|
#magic that turns the results object into an array:
|
||||||
node for node in result
|
node for node in result
|
||||||
addTo = (parent, children...) ->
|
addTo = (parent, children...) ->
|
||||||
for child in children
|
for child in children
|
||||||
parent.appendChild child
|
parent.appendChild child
|
||||||
getConfig = (name) ->
|
getConfig = (name) ->
|
||||||
GM_getValue(name, config[name][0])
|
GM_getValue name, config[name][0]
|
||||||
getTime = ->
|
getTime = ->
|
||||||
Math.floor(new Date().getTime() / 1000)
|
Math.floor(new Date().getTime() / 1000)
|
||||||
hide = (el) ->
|
hide = (el) ->
|
||||||
@ -153,9 +153,9 @@ n = (tag, props) -> #new
|
|||||||
if props then m el, props
|
if props then m el, props
|
||||||
el
|
el
|
||||||
remove = (el) ->
|
remove = (el) ->
|
||||||
el.parentNode.removeChild(el)
|
el.parentNode.removeChild el
|
||||||
replace = (root, el) ->
|
replace = (root, el) ->
|
||||||
root.parentNode.replaceChild(el, root)
|
root.parentNode.replaceChild el, root
|
||||||
show = (el) ->
|
show = (el) ->
|
||||||
el.style.display = ''
|
el.style.display = ''
|
||||||
slice = (arr, id) ->
|
slice = (arr, id) ->
|
||||||
@ -166,7 +166,7 @@ slice = (arr, id) ->
|
|||||||
l = arr.length
|
l = arr.length
|
||||||
while (i < l)
|
while (i < l)
|
||||||
if id == arr[i].id
|
if id == arr[i].id
|
||||||
arr.splice(i, 1)
|
arr.splice i, 1
|
||||||
return arr
|
return arr
|
||||||
i++
|
i++
|
||||||
tn = (s) ->
|
tn = (s) ->
|
||||||
@ -231,10 +231,10 @@ expandComment = (e) ->
|
|||||||
onloadComment(this.responseText, a, href)
|
onloadComment(this.responseText, a, href)
|
||||||
r.open('GET', href, true)
|
r.open('GET', href, true)
|
||||||
r.send()
|
r.send()
|
||||||
xhrs.push({
|
xhrs.push {
|
||||||
r: r,
|
r: r,
|
||||||
id: href.match(/\d+/)[0]
|
id: href.match(/\d+/)[0]
|
||||||
})
|
}
|
||||||
|
|
||||||
expandThread = ->
|
expandThread = ->
|
||||||
id = x('preceding-sibling::input[1]', this).name
|
id = x('preceding-sibling::input[1]', this).name
|
||||||
@ -243,41 +243,56 @@ expandThread = ->
|
|||||||
if span.textContent[0] is '-'
|
if span.textContent[0] is '-'
|
||||||
#goddamit moot
|
#goddamit moot
|
||||||
num = if board is 'b' then 3 else 5
|
num = if board is 'b' then 3 else 5
|
||||||
table = x("following::br[@clear][1]/preceding::table[#{num}]", span)
|
table = x "following::br[@clear][1]/preceding::table[#{num}]", span
|
||||||
while (prev = table.previousSibling) and (prev.nodeName is 'TABLE')
|
while (prev = table.previousSibling) and (prev.nodeName is 'TABLE')
|
||||||
remove(prev)
|
remove prev
|
||||||
span.textContent = span.textContent.replace('-', '+')
|
span.textContent = span.textContent.replace '-', '+'
|
||||||
return
|
return
|
||||||
span.textContent = span.textContent.replace('+', 'X Loading...')
|
span.textContent = span.textContent.replace '+', 'X Loading...'
|
||||||
#load cache
|
#load cache
|
||||||
for xhr in xhrs
|
for xhr in xhrs
|
||||||
if xhr.id == id
|
if xhr.id == id
|
||||||
#why can't we just xhr.r.onload()?
|
#why can't we just xhr.r.onload()?
|
||||||
onloadThread(xhr.r.responseText, span)
|
onloadThread xhr.r.responseText, span
|
||||||
return
|
return
|
||||||
#create new request
|
#create new request
|
||||||
r = new XMLHttpRequest()
|
r = new XMLHttpRequest()
|
||||||
r.onload = ->
|
r.onload = ->
|
||||||
onloadThread(this.responseText, span)
|
onloadThread this.responseText, span
|
||||||
r.open('GET', "res/#{id}", true)
|
r.open 'GET', "res/#{id}", true
|
||||||
r.send()
|
r.send()
|
||||||
xhrs.push({
|
xhrs.push {
|
||||||
r: r,
|
r: r,
|
||||||
id: id
|
id: id
|
||||||
})
|
}
|
||||||
|
|
||||||
|
formSubmit = (e) ->
|
||||||
|
if span = @nextSibling
|
||||||
|
remove(span)
|
||||||
|
recaptcha = $('input[name=recaptcha_response_field]', this)
|
||||||
|
if recaptcha.value
|
||||||
|
$('#qr input[title=autohide]:not(:checked)')?.click()
|
||||||
|
else
|
||||||
|
e.preventDefault()
|
||||||
|
span = n 'span',
|
||||||
|
className: 'error'
|
||||||
|
textContent: 'You forgot to type in the verification.'
|
||||||
|
addTo @parentNode, span
|
||||||
|
alert 'You forgot to type in the verification.'
|
||||||
|
recaptcha.focus()
|
||||||
|
|
||||||
hideReply = (reply) ->
|
hideReply = (reply) ->
|
||||||
if p = this.parentNode
|
if p = this.parentNode
|
||||||
reply = p.nextSibling
|
reply = p.nextSibling
|
||||||
hiddenReplies.push({
|
hiddenReplies.push {
|
||||||
id: reply.id
|
id: reply.id
|
||||||
timestamp: getTime()
|
timestamp: getTime()
|
||||||
})
|
}
|
||||||
GM_setValue("hiddenReplies/#{BOARD}/", JSON.stringify(hiddenReplies))
|
GM_setValue("hiddenReplies/#{BOARD}/", JSON.stringify(hiddenReplies))
|
||||||
name = $('span.commentpostername', reply).textContent
|
name = $('span.commentpostername', reply).textContent
|
||||||
trip = $('span.postertrip', reply)?.textContent || ''
|
trip = $('span.postertrip', reply)?.textContent or ''
|
||||||
table = x('ancestor::table', reply)
|
table = x 'ancestor::table', reply
|
||||||
hide(table)
|
hide table
|
||||||
if getConfig 'Show Stubs'
|
if getConfig 'Show Stubs'
|
||||||
a = n 'a',
|
a = n 'a',
|
||||||
textContent: "[ + ] #{name} #{trip}"
|
textContent: "[ + ] #{name} #{trip}"
|
||||||
@ -315,8 +330,8 @@ iframeLoad = ->
|
|||||||
if iframeLoop = !iframeLoop
|
if iframeLoop = !iframeLoop
|
||||||
return
|
return
|
||||||
$('iframe').src = 'about:blank'
|
$('iframe').src = 'about:blank'
|
||||||
qr = $('#qr')
|
qr = $ '#qr'
|
||||||
if error = GM_getValue('error')
|
if error = GM_getValue 'error'
|
||||||
span = n 'span',
|
span = n 'span',
|
||||||
textContent: error
|
textContent: error
|
||||||
className: 'error'
|
className: 'error'
|
||||||
@ -325,7 +340,7 @@ iframeLoad = ->
|
|||||||
else if REPLY and getConfig 'Persistent QR'
|
else if REPLY and getConfig 'Persistent QR'
|
||||||
$('textarea', qr).value = ''
|
$('textarea', qr).value = ''
|
||||||
$('input[name=recaptcha_response_field]', qr).value = ''
|
$('input[name=recaptcha_response_field]', qr).value = ''
|
||||||
submit = $('input[type=submit]', qr)
|
submit = $ 'input[type=submit]', qr
|
||||||
submit.value = 30
|
submit.value = 30
|
||||||
submit.disabled = true
|
submit.disabled = true
|
||||||
window.setTimeout cooldown, 1000
|
window.setTimeout cooldown, 1000
|
||||||
@ -341,14 +356,14 @@ nodeInserted = (e) ->
|
|||||||
target = e.target
|
target = e.target
|
||||||
if target.nodeName is 'TABLE'
|
if target.nodeName is 'TABLE'
|
||||||
for callback in callbacks
|
for callback in callbacks
|
||||||
callback(target)
|
callback target
|
||||||
else if target.id is 'recaptcha_challenge_field' and qr = $ '#qr'
|
else if target.id is 'recaptcha_challenge_field' and qr = $ '#qr'
|
||||||
$('#recaptcha_image img', qr).src = "http://www.google.com/recaptcha/api/image?c=" + target.value
|
$('#recaptcha_image img', qr).src = "http://www.google.com/recaptcha/api/image?c=" + target.value
|
||||||
$('#recaptcha_challenge_field', qr).value = target.value
|
$('#recaptcha_challenge_field', qr).value = target.value
|
||||||
|
|
||||||
onloadComment = (responseText, a, href) ->
|
onloadComment = (responseText, a, href) ->
|
||||||
[_, op, id] = href.match(/(\d+)#(\d+)/)
|
[_, op, id] = href.match /(\d+)#(\d+)/
|
||||||
[replies, opbq] = parseResponse(responseText)
|
[replies, opbq] = parseResponse responseText
|
||||||
if id is op
|
if id is op
|
||||||
html = opbq.innerHTML
|
html = opbq.innerHTML
|
||||||
else
|
else
|
||||||
@ -357,23 +372,23 @@ onloadComment = (responseText, a, href) ->
|
|||||||
for reply in replies
|
for reply in replies
|
||||||
if reply.id == id
|
if reply.id == id
|
||||||
html = $('blockquote', reply).innerHTML
|
html = $('blockquote', reply).innerHTML
|
||||||
bq = x('ancestor::blockquote', a)
|
bq = x 'ancestor::blockquote', a
|
||||||
bq.innerHTML = html
|
bq.innerHTML = html
|
||||||
|
|
||||||
onloadThread = (responseText, span) ->
|
onloadThread = (responseText, span) ->
|
||||||
[replies, opbq] = parseResponse(responseText)
|
[replies, opbq] = parseResponse responseText
|
||||||
span.textContent = span.textContent.replace('X Loading...', '- ')
|
span.textContent = span.textContent.replace 'X Loading...', '- '
|
||||||
#make sure all comments are fully expanded
|
#make sure all comments are fully expanded
|
||||||
span.previousSibling.innerHTML = opbq.innerHTML
|
span.previousSibling.innerHTML = opbq.innerHTML
|
||||||
while (next = span.nextSibling) and not next.clear#<br clear>
|
while (next = span.nextSibling) and not next.clear#<br clear>
|
||||||
remove(next)
|
remove next
|
||||||
if next
|
if next
|
||||||
for reply in replies
|
for reply in replies
|
||||||
inBefore next, x('ancestor::table', reply)
|
inBefore next, x('ancestor::table', reply)
|
||||||
else#threading
|
else#threading
|
||||||
div = span.parentNode
|
div = span.parentNode
|
||||||
for reply in replies
|
for reply in replies
|
||||||
addTo div, x('ancestor::table', reply)
|
addTo div, x 'ancestor::table', reply
|
||||||
|
|
||||||
options = ->
|
options = ->
|
||||||
if div = $ '#options'
|
if div = $ '#options'
|
||||||
@ -398,8 +413,8 @@ options = ->
|
|||||||
addTo d.body, div
|
addTo d.body, div
|
||||||
|
|
||||||
optionsClose = ->
|
optionsClose = ->
|
||||||
div = this.parentNode.parentNode
|
div = @parentNode.parentNode
|
||||||
inputs = $$('input', div)
|
inputs = $$ 'input', div
|
||||||
for input in inputs
|
for input in inputs
|
||||||
GM_setValue(input.name, input.checked)
|
GM_setValue(input.name, input.checked)
|
||||||
GM_setValue 'saucePrefix', $('textarea', div).value
|
GM_setValue 'saucePrefix', $('textarea', div).value
|
||||||
@ -408,12 +423,12 @@ optionsClose = ->
|
|||||||
parseResponse = (responseText) ->
|
parseResponse = (responseText) ->
|
||||||
body = n 'body',
|
body = n 'body',
|
||||||
innerHTML: responseText
|
innerHTML: responseText
|
||||||
replies = $$('td.reply', body)
|
replies = $$ 'td.reply', body
|
||||||
opbq = $('blockquote', body)
|
opbq = $ 'blockquote', body
|
||||||
return [replies, opbq]
|
return [replies, opbq]
|
||||||
|
|
||||||
quickReply = (e) ->
|
quickReply = (e) ->
|
||||||
unless qr = $('#qr')
|
unless qr = $ '#qr'
|
||||||
#make quick reply dialog
|
#make quick reply dialog
|
||||||
qr = AEOS.makeDialog 'qr', 'topleft'
|
qr = AEOS.makeDialog 'qr', 'topleft'
|
||||||
titlebar = n 'div',
|
titlebar = n 'div',
|
||||||
@ -433,13 +448,13 @@ quickReply = (e) ->
|
|||||||
listener: ['click', close]
|
listener: ['click', close]
|
||||||
addTo titlebar, autohideB, tn(' '), closeB
|
addTo titlebar, autohideB, tn(' '), closeB
|
||||||
form = $ 'form[name=post]'
|
form = $ 'form[name=post]'
|
||||||
clone = form.cloneNode(true)
|
clone = form.cloneNode true
|
||||||
#remove recaptcha scripts
|
#remove recaptcha scripts
|
||||||
for script in $$ 'script', clone
|
for script in $$ 'script', clone
|
||||||
remove script
|
remove script
|
||||||
$('input[name=recaptcha_response_field]', clone).
|
m $('input[name=recaptcha_response_field]', clone),
|
||||||
addEventListener('keydown', recaptchaListener, true)
|
listener: ['keydown', recaptchaListener]
|
||||||
clone.addEventListener('submit', submit, true)
|
clone.addEventListener 'submit', formSubmit, true
|
||||||
clone.target = 'iframe'
|
clone.target = 'iframe'
|
||||||
if not REPLY
|
if not REPLY
|
||||||
#figure out which thread we're replying to
|
#figure out which thread we're replying to
|
||||||
@ -520,21 +535,6 @@ showThread = ->
|
|||||||
slice hiddenThreads, id
|
slice hiddenThreads, id
|
||||||
GM_setValue("hiddenThreads/#{BOARD}/", JSON.stringify(hiddenThreads))
|
GM_setValue("hiddenThreads/#{BOARD}/", JSON.stringify(hiddenThreads))
|
||||||
|
|
||||||
submit = (e) ->
|
|
||||||
if span = @nextSibling
|
|
||||||
remove(span)
|
|
||||||
recaptcha = $('input[name=recaptcha_response_field]', this)
|
|
||||||
if recaptcha.value
|
|
||||||
$('#qr input[title=autohide]:not(:checked)')?.click()
|
|
||||||
else
|
|
||||||
e.preventDefault()
|
|
||||||
span = n 'span',
|
|
||||||
className: 'error'
|
|
||||||
textContent: 'You forgot to type in the verification.'
|
|
||||||
addTo @parentNode, span
|
|
||||||
alert 'You forgot to type in the verification.'
|
|
||||||
recaptcha.focus()
|
|
||||||
|
|
||||||
stopPropagation = (e) ->
|
stopPropagation = (e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
@ -569,10 +569,10 @@ watch = ->
|
|||||||
text = "/#{BOARD}/ - " +
|
text = "/#{BOARD}/ - " +
|
||||||
x('following-sibling::blockquote', this).textContent.slice(0,25)
|
x('following-sibling::blockquote', this).textContent.slice(0,25)
|
||||||
watched[BOARD] or= []
|
watched[BOARD] or= []
|
||||||
watched[BOARD].push({
|
watched[BOARD].push {
|
||||||
id: id,
|
id: id,
|
||||||
text: text
|
text: text
|
||||||
})
|
}
|
||||||
else
|
else
|
||||||
this.src = favEmpty
|
this.src = favEmpty
|
||||||
watched[BOARD] = slice(watched[BOARD], id)
|
watched[BOARD] = slice(watched[BOARD], id)
|
||||||
@ -617,10 +617,10 @@ if location.hostname.split('.')[0] is 'sys'
|
|||||||
if thread is '0'
|
if thread is '0'
|
||||||
board = $('meta', d).content.match(/4chan.org\/(\w+)\//)[1]
|
board = $('meta', d).content.match(/4chan.org\/(\w+)\//)[1]
|
||||||
watched[board] or= []
|
watched[board] or= []
|
||||||
watched[board].push({
|
watched[board].push {
|
||||||
id: id,
|
id: id,
|
||||||
text: GM_getValue('autoText')
|
text: GM_getValue('autoText')
|
||||||
})
|
}
|
||||||
GM_setValue('watched', JSON.stringify(watched))
|
GM_setValue('watched', JSON.stringify(watched))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -724,7 +724,6 @@ GM_addStyle('
|
|||||||
}
|
}
|
||||||
')
|
')
|
||||||
|
|
||||||
|
|
||||||
#main part 2...
|
#main part 2...
|
||||||
AEOS.init()
|
AEOS.init()
|
||||||
if navtopr = $ '#navtopr a'
|
if navtopr = $ '#navtopr a'
|
||||||
|
|||||||
46
4chan_x.js
46
4chan_x.js
@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var $, $$, AEOS, BOARD, DAY, PAGENUM, REPLY, THREAD_ID, _, _i, _len, _ref, a, addTo, arr, as, autoWatch, autohide, b, board, callback, callbacks, clearHidden, close, config, cooldown, cutoff, d, defaultSaucePrefix, delform, down, editSauce, el, expandComment, expandThread, favEmpty, favNormal, favicon, getConfig, getTime, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, iframeLoop, inAfter, inBefore, inputs, l, l1, lastChecked, m, magic, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, r, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, submit, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs;
|
var $, $$, AEOS, BOARD, DAY, PAGENUM, REPLY, THREAD_ID, _, _i, _len, _ref, a, addTo, arr, as, autoWatch, autohide, b, board, callback, callbacks, clearHidden, close, config, cooldown, cutoff, d, defaultSaucePrefix, delform, down, editSauce, el, expandComment, expandThread, favEmpty, favNormal, favicon, formSubmit, getConfig, getTime, head, hiddenReplies, hiddenThreads, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, iframeLoop, inAfter, inBefore, inputs, l, l1, lastChecked, m, magic, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, r, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watched, watcher, watcherUpdate, x, xhrs;
|
||||||
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
||||||
config = {
|
config = {
|
||||||
'Thread Hiding': [true, 'Hide entire threads'],
|
'Thread Hiding': [true, 'Hide entire threads'],
|
||||||
@ -336,6 +336,25 @@
|
|||||||
id: id
|
id: id
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
formSubmit = function(e) {
|
||||||
|
var _ref, _ref2, recaptcha, span;
|
||||||
|
if (span = this.nextSibling) {
|
||||||
|
remove(span);
|
||||||
|
}
|
||||||
|
recaptcha = $('input[name=recaptcha_response_field]', this);
|
||||||
|
if (recaptcha.value) {
|
||||||
|
return (typeof (_ref2 = ((_ref = $('#qr input[title=autohide]:not(:checked)')))) === "undefined" || _ref2 === null) ? undefined : _ref2.click();
|
||||||
|
} else {
|
||||||
|
e.preventDefault();
|
||||||
|
span = n('span', {
|
||||||
|
className: 'error',
|
||||||
|
textContent: 'You forgot to type in the verification.'
|
||||||
|
});
|
||||||
|
addTo(this.parentNode, span);
|
||||||
|
alert('You forgot to type in the verification.');
|
||||||
|
return recaptcha.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
hideReply = function(reply) {
|
hideReply = function(reply) {
|
||||||
var _ref, _ref2, a, div, name, p, table, trip;
|
var _ref, _ref2, a, div, name, p, table, trip;
|
||||||
if (p = this.parentNode) {
|
if (p = this.parentNode) {
|
||||||
@ -564,8 +583,10 @@
|
|||||||
script = _ref[_i];
|
script = _ref[_i];
|
||||||
remove(script);
|
remove(script);
|
||||||
}
|
}
|
||||||
$('input[name=recaptcha_response_field]', clone).addEventListener('keydown', recaptchaListener, true);
|
m($('input[name=recaptcha_response_field]', clone), {
|
||||||
clone.addEventListener('submit', submit, true);
|
listener: ['keydown', recaptchaListener]
|
||||||
|
});
|
||||||
|
clone.addEventListener('submit', formSubmit, true);
|
||||||
clone.target = 'iframe';
|
clone.target = 'iframe';
|
||||||
if (!REPLY) {
|
if (!REPLY) {
|
||||||
xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]';
|
xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]';
|
||||||
@ -664,25 +685,6 @@
|
|||||||
slice(hiddenThreads, id);
|
slice(hiddenThreads, id);
|
||||||
return GM_setValue("hiddenThreads/" + (BOARD) + "/", JSON.stringify(hiddenThreads));
|
return GM_setValue("hiddenThreads/" + (BOARD) + "/", JSON.stringify(hiddenThreads));
|
||||||
};
|
};
|
||||||
submit = function(e) {
|
|
||||||
var _ref, _ref2, recaptcha, span;
|
|
||||||
if (span = this.nextSibling) {
|
|
||||||
remove(span);
|
|
||||||
}
|
|
||||||
recaptcha = $('input[name=recaptcha_response_field]', this);
|
|
||||||
if (recaptcha.value) {
|
|
||||||
return (typeof (_ref2 = ((_ref = $('#qr input[title=autohide]:not(:checked)')))) === "undefined" || _ref2 === null) ? undefined : _ref2.click();
|
|
||||||
} else {
|
|
||||||
e.preventDefault();
|
|
||||||
span = n('span', {
|
|
||||||
className: 'error',
|
|
||||||
textContent: 'You forgot to type in the verification.'
|
|
||||||
});
|
|
||||||
addTo(this.parentNode, span);
|
|
||||||
alert('You forgot to type in the verification.');
|
|
||||||
return recaptcha.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
stopPropagation = function(e) {
|
stopPropagation = function(e) {
|
||||||
return e.stopPropagation();
|
return e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user