Skip to content

Conversation

@cmgchess
Copy link
Contributor

@cmgchess cmgchess commented Dec 4, 2023

#14126
EDIT - https://stackoverflow.com/questions/67286355/div-innertext-loses-new-lines-after-setting-display-to-none is the reason
not sure if this is the proper fix

without blocked button
image

for some reason idk, when blocked button this happens, so it doesn't get matched by the regex
image

image
image

@cmgchess cmgchess marked this pull request as draft December 5, 2023 06:48
@cmgchess
Copy link
Contributor Author

cmgchess commented Dec 5, 2023

oof still breaking if no :

@cmgchess cmgchess marked this pull request as ready for review December 5, 2023 07:45
@cmgchess
Copy link
Contributor Author

cmgchess commented Dec 5, 2023

can remove the innerText match and use only the innerHtml. thoughts?

});
$('.forum-post__message').each(function (this: HTMLElement) {
if (this.innerText.match(/(^|\n)>/)) {
const isVisible = window.getComputedStyle(this).display !== 'none';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of getComputedStyle, it's hacky and slow - and runs on each blog post. Can we test a class instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't know this 😮

@ornicar
Copy link
Collaborator

ornicar commented Dec 5, 2023

Can we instead parse the blockquotes at the moment the message is displayed, when the user clicks the "show blocked message" button?

@cmgchess
Copy link
Contributor Author

cmgchess commented Dec 5, 2023

Can we instead parse the blockquotes at the moment the message is displayed, when the user clicks the "show blocked message" button?

i tried something like this after reverting my prev changes, but now there is some code duplication. i could move it to a separate function but then don't know where to put it.

  $('.forum-post__blocked button').on('click', e => {
    const el = (e.target as HTMLElement).parentElement!;
    const message = el.querySelector('.forum-post__message') as HTMLElement;
    if (message.innerHTML.match(/(^|<br>)&gt;/)) {
      const hiddenQuotes = '<span class=hidden-quotes>&gt;</span>';
      let result = '';
      let quote = [];
      for (const line of message.innerHTML.split('<br>')) {
        if (line.startsWith('&gt;')) quote.push(hiddenQuotes + line.substring(4).trim());
        else {
          if (quote.length > 0) {
            result += `<blockquote>${quote.join('<br>')}</blockquote>`;
            quote = [];
          }
          result += line + '<br>';
        }
      }
      if (quote.length > 0) result += `<blockquote>${quote.join('<br>')}</blockquote>`;
      message.innerHTML = result;
    }    
    $(el).replaceWith($('.forum-post__message', el));
  });

* master:
  refactor ui/lobby modals
  fix style of decline challenge page
  fix typing & usage of lichess.asset.userComplete
  Update list.txt
  add 2024 flair
  hide online status when challenging
@ornicar ornicar merged commit 5aa726c into lichess-org:master Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants