inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 20, 2020 5:01:27 GMT -8
Hi guys, I have been getting a lot of help from Scott , Craig , Retread & Michael with code that removes unnecessary line returns at the end of posts. I needed the code as some members of my forum - 1 in particular, has a puculiar habit of hitting the return key at the end of his posts to add anything up to 15 blank lines at the foot of his posts. Rather than having to go back in and edit his posts all the time, I sought help and was directed to some excellent code by elli . This was then added to by Michael and is working very well. However, the one member of my forum that I mentioned above, has posted again today and added 5 line breaks at the foot of his post, all of which are showing even though the new code is in place. Here is a link to the post in question: Link Is there anything in this code that I can change to limit the line breaks at the foot of all posts to just 2 line breaks? The code is currently in my Global Footer. <script> /* limit long strings of breaks to just two breaks */ function removeTrailingBreaksInPosts() { var $postMessage = $('.posts .post .message'); $postMessage.each(function() { var $this = $(this); var $postMessageBody = $this.html().replace(/(<br\s*\/?>\s*){3,}/g, '<br><br>'); $this.html($postMessageBody); }); } $(document).ready(function() { removeTrailingBreaksInPosts(); proboards.on('pageChange', removeTrailingBreaksInPosts); proboards.on('afterSearch', removeTrailingBreaksInPosts); }); </script>
Any help would be appreciated - thank you. GH.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 20, 2020 9:54:26 GMT -8
In addition to the above request, I have been given some good advice from Scott (Thanks Scott) - to have a word with the particular member in question rather than rely on the code. Though I did initially consider this option, I'm hesitant to do this as the member is a hugely valued member and contributer to my forum and I don't want to give any cause for him to refrain from posting. I've also been advised that though the code removes the line breaks in the desktop version of my forum, it will have no effect for members viewing my forum via the mobile version. This isn't an issue as I have disabled Mobile View from my Admin Panel. So, I am still looking for any advice as per my opening post.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 21, 2020 7:53:40 GMT -8
In fact, the code doesn't appear to be working now. The same member has added 5 line returns in a post today and they are all showing.
Back to the drawing board so any assistance would be greatly appreciateed.
GH.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on May 21, 2020 13:22:48 GMT -8
In fact, the code doesn't appear to be working now. The same member has added 5 line returns in a post today and they are all showing. Back to the drawing board so any assistance would be greatly appreciateed. GH. Your member has started wrapping his <br> tags in <div> tags, that's why the code has stopped working. This can be corrected, but then he'll start wrapping them in <span> tags, then <font> tags, then <b> tags.. The list goes on... In seems like your member is dead set on posting multiple line breaks at the end of his post, so this will be pretty difficult to rule out every way he can do it.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 21, 2020 13:42:22 GMT -8
Hi Todge - thanks for looking into this, much appreciated. When you say it can be corrected,how do you mean? I'm willing to give any workaround a try. For sure if he then deliberately finds a way around that, I will be forced to contact him about it. Thanks again TodgeGH.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on May 21, 2020 15:22:25 GMT -8
Hi Todge - thanks for looking into this, much appreciated. When you say it can be corrected,how do you mean? I'm willing to give any workaround a try. For sure if he then deliberately finds a way around that, I will be forced to contact him about it. Thanks again Todge GH. You could try this... <script> /* Remove line breaks from end of post */ function remove_break_tags(post) { $(post).html($(post).html().replace(/<(div|span|font|b|i|u|s)><\/(div|span|font|b|i|u|s)>/ig,'')); $(post).html($(post).html().replace(/((<[div|span|font|b|i|u|s]>)?<br\/?>(<\/[div|span|font|b|i|u|s]>)?)+$/i,'')); return; }
$(document).ready(function(){ $('article > .message').each(function(){ remove_break_tags($(this)); }); proboards.on('pageChange', function(){ $('article > .message').each(function(){ remove_break_tags($(this)); }); }); }); </script>
but it's far from infallable.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 21, 2020 22:44:14 GMT -8
Thanks for that Todge - I'll give it a tryout. I've just spent some time going through this users older posts and noticed in particular a post from last year, when I look at the BBCode, it is riddled with [ div] tags This PostWhat is he doing to get these tags? Thanks again Todge EDIT: I have just replaced the old code in the Global Footer with the new code above but there are still 5 line breaks showing at the end of this post. Example
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on May 22, 2020 6:10:42 GMT -8
Another option to try is find the last element with actual text content, and then delete any tags with just <br>s in them: <script> /** * Remove tags with just a <br> in them at the end of a post **/ function removeEmptyElementsAtEndOfPost(){ document.querySelectorAll('.message').forEach((el) => { var elementsWithContent = Array.from(el.children).filter(function(child){ return child.textContent.length > 0; }); if(elementsWithContent.length > 0){ var lastElementWithContent = elementsWithContent[elementsWithContent.length - 1]; var nextSibling = lastElementWithContent.nextElementSibling; var toRemove = []; while(nextSibling != null){ if(Array.from(nextSibling.children).filter(function(child){ return child.nodeName === 'BR'; }).length === nextSibling.children.length){ toRemove.push(nextSibling); } nextSibling = nextSibling.nextElementSibling; } toRemove.forEach(function(el){ el.parentNode.removeChild(el); }); } }); }
$(document).ready(function(){ removeEmptyElementsAtEndOfPost(); proboards.on('pageChange', removeEmptyElementsAtEndOfPost);
proboards.on('afterSearch', removeEmptyElementsAtEndOfPost); }); </script>
|
|
Kami
Forum Cat
Posts: 40,201
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,201
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on May 22, 2020 6:50:27 GMT -8
Just some food for thought. You put in preventative measures to strip this extra spacing with as little interference to day to day posting as possible, but the member intentionally circumvented this.
The only way to work around the codes that have been provided for you is to intentionally change how the line breaks appear (eg if a code just looks for the letter X, and he wraps the X in bold tags, it won't be recognised as being X). It would take a moderate amount of effort to circumvent the code provided since they would need to intentionally look for what is preventing them from adding extra spaces.
I get the activity level, but I think you need to talk with them sooner rather than later. Default to trust and don't assume malicious intent, but it is worth opening a dialogue to ask why they feel the need to add the spacing. Perhaps it's a clarity issue that can be addressed by modifying the theme to show more spacing between posts so the text doesn't all flow together, or something of that nature. Work with your member, not against them!
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on May 22, 2020 7:10:45 GMT -8
And if all the above still fail, give this a try...
<script> function remove_break_tags(post) { $(post).html($(post).html().replace(/((<\w{1,5}>)?(<br\/?>)?(<\/\w{1,5}>)?)+$/i,'')); return; }
$(document).ready(function(){ $('article > .message').each(function(){ remove_break_tags($(this)); }); proboards.on('pageChange', function(){ $('article > .message').each(function(){ remove_break_tags($(this)); }); }); }); </script>
It should (hopefully) block pretty much any tag that he tries to wrap his line breaks in.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 22, 2020 7:19:07 GMT -8
All good stuff folks. Thanks for the code Todge & Bennett 🚀I'll give it a try. I just don't understand what the member is doing to get so many div tags in a post. What does anyone have to do to produce a div tag? This particular post of his is riddled with div tags Member PostI'm as interested in what he is doing to get the div tags as I am to know why. Thanks again. GH.
|
|
Kami
Forum Cat
Posts: 40,201
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,201
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on May 22, 2020 7:34:36 GMT -8
It could be something in their browser addons that's appending them to the post. It's not super frequent this happens but it's not unheard of.
Hitting enter several times also generates empty div tags to account for the space (otherwise it would not render in HTML).
You could also just manually type out the div.
The last two are the most likely scenarios.
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 22, 2020 8:35:30 GMT -8
It could be something in their browser addons that's appending them to the post. It's not super frequent this happens but it's not unheard of. Hitting enter several times also generates empty div tags to account for the space (otherwise it would not render in HTML). You could also just manually type out the div. The last two are the most likely scenarios. Thanks for the explanation Kami Forgive my ignorance on these matters, but what is the difference between a div tag and a br tag ([div} & [br}) GH.
|
|
Kami
Forum Cat
Posts: 40,201
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,201
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on May 22, 2020 13:46:51 GMT -8
It could be something in their browser addons that's appending them to the post. It's not super frequent this happens but it's not unheard of. Hitting enter several times also generates empty div tags to account for the space (otherwise it would not render in HTML). You could also just manually type out the div. The last two are the most likely scenarios. Thanks for the explanation Kami Forgive my ignorance on these matters, but what is the difference between a div tag and a br tag ([div} & [br}) GH. div is a DIVision, br is a line BReak (:
|
|
inherit
219572
0
Oct 25, 2023 2:12:01 GMT -8
Gene Hunt
634
March 2015
genehunt
|
Post by Gene Hunt on May 22, 2020 13:50:07 GMT -8
This is where I get confused. A BReak is produced by a press of the return key. Yes? How do you produce a DIVision ? Thanks Kami
|
|