improve the "show more" button

pull/90/head
Aevann 2023-01-21 01:47:27 +02:00
parent 4b6baac968
commit c560d1d9fe
4 changed files with 9 additions and 9 deletions

View File

@ -112,6 +112,12 @@ if (reload_page) {
}
function register_new_elements(e) {
for (const element of document.getElementsByClassName('showmore')) {
element.onclick = () => {
showmore(element)
};
}
const onclick = e.querySelectorAll('[data-onclick]');
for (const element of onclick) {
element.onclick = ()=>{execute(element, 'onclick')};

View File

@ -282,12 +282,6 @@ function showmore(t) {
t.innerHTML = 'SHOW LESS'
}
for (const element of document.getElementsByClassName('showmore')) {
element.onclick = () => {
showmore(element)
};
}
function formatDate(d) {
let year = d.getFullYear();
let monthAbbr = d.toLocaleDateString('en-us', {month: 'short'});

View File

@ -107,7 +107,7 @@ color_regex = re.compile("[a-f0-9]{6}", flags=re.A)
# lazy match on the {}?, only match if there is trailing stuff
# Specifically match Snappy's way of formatting, this might break some losers' comments.
showmore_regex = re.compile(r"^(.{3000,}?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
showmore_regex = re.compile(r"^((.{3000,}?|(.*?<.*?){10,})?<\/p>(?:<\/li><\/ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)

View File

@ -410,8 +410,8 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
if '<pre>' not in sanitized and not sidebar:
sanitized = sanitized.replace('\n','')
if showmore and len(sanitized) > 3500:
sanitized = showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>', sanitized, count=1)
if showmore and len(sanitized) > 3500 or sanitized.count('<') > 15:
sanitized = showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\4</d>', sanitized, count=1)
return sanitized.strip()