forked from rDrama/rDrama
improve the showmore algo
parent
ec1b304d0d
commit
9529cbbd61
|
@ -260,7 +260,11 @@ function changename(s1,s2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showmore(t) {
|
function showmore(t) {
|
||||||
const div = t.parentElement.nextElementSibling
|
let div = t
|
||||||
|
while (!(div.id && div.id.startsWith('comment-text-'))){
|
||||||
|
div = div.parentElement
|
||||||
|
}
|
||||||
|
div = div.getElementsByTagName('d')[0]
|
||||||
div.classList.toggle('d-none')
|
div.classList.toggle('d-none')
|
||||||
if (div.classList.contains('d-none'))
|
if (div.classList.contains('d-none'))
|
||||||
t.innerHTML = 'SHOW MORE'
|
t.innerHTML = 'SHOW MORE'
|
||||||
|
|
|
@ -106,7 +106,7 @@ color_regex = re.compile("[a-f0-9]{6}", flags=re.A)
|
||||||
|
|
||||||
# lazy match on the .*?, only match if there is trailing stuff
|
# lazy match on the .*?, only match if there is trailing stuff
|
||||||
# Specifically match Snappy's way of formatting, this might break some losers' comments.
|
# Specifically match Snappy's way of formatting, this might break some losers' comments.
|
||||||
showmore_regex = re.compile(r"^(.*?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
|
showmore_regex = re.compile(r"^(.*?<\/[a-z]+>(?:<\/li><\/ul>)?)(\s*<[a-z]+>.*)", flags=re.A|re.DOTALL)
|
||||||
|
|
||||||
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)
|
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)
|
||||||
|
|
||||||
|
|
|
@ -537,14 +537,14 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
||||||
CHARLIMIT = 3000
|
CHARLIMIT = 3000
|
||||||
pos = 0
|
pos = 0
|
||||||
for _ in range(20):
|
for _ in range(20):
|
||||||
pos = sanitized.find('</p>', pos + 4)
|
pos = sanitized.find('>', pos + 4)
|
||||||
if pos < 0:
|
if pos < 0:
|
||||||
break
|
break
|
||||||
if (pos < 0 and len(sanitized) > CHARLIMIT) or pos > CHARLIMIT:
|
if (pos < 0 and len(sanitized) > CHARLIMIT) or pos > CHARLIMIT:
|
||||||
pos = CHARLIMIT - 500
|
pos = CHARLIMIT - 500
|
||||||
if pos >= 0:
|
if pos >= 0:
|
||||||
sanitized = (sanitized[:pos] +
|
sanitized = (sanitized[:pos] +
|
||||||
showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>',
|
showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p></ul><d class="d-none">\2</d>',
|
||||||
sanitized[pos:], count=1))
|
sanitized[pos:], count=1))
|
||||||
|
|
||||||
return sanitized.strip()
|
return sanitized.strip()
|
||||||
|
|
Loading…
Reference in New Issue