inherit
222558
0
Nov 26, 2024 20:20:42 GMT -8
Willow
This font!
835
June 2015
willowelf
|
Post by Willow on Aug 19, 2023 16:19:05 GMT -8
FYI - I think this would have gone on the old "coding" board but I don't know where to apply this because I don't know where if what I propose below is possible where one would do it.
So, is it possible to have a thread (if not a thread maybe a whole board?) that whenever anyone/everyone posts there, the entirety of the post is placed within the spoiler tags automatically?
If that isn't clear let me know.
Thank you!
|
|
inherit
140147
0
Nov 19, 2024 5:07:22 GMT -8
Nscalerr
Throw me to the wolves and I'll return leading the pack!
3,043
May 2009
nscalerr
|
Post by Nscalerr on Aug 20, 2023 0:33:22 GMT -8
Hi WillowI have a feeling having it happen automatically may not be allowed under the developer guidelines for plugins. Staff will be able to confirm either way.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Aug 20, 2023 17:22:12 GMT -8
If you use the submit event or the built-in validation process to modify the post before sending, then it would be within the rules since it was initiated by the user's action (clicking the Post Quick Reply or Create Post button); Give the code posted below a try in the header(s) of the board where you want automatic spoiler tags added. You could alternatively add it to the header of a category in order to affect all the boards within that category. <script> /* automatically Add Spoiler Around Posts (Installation: Board Header) */ $(document).on('formcreate', (ev)=>{ if(ev.target.attributes['action']){ const validation = { name : "spoiler_exists", field : "message", opts : { area_of_effect : "" }, message:"" } let form = null; if(/\/(post|thread)\//.test(ev.target.attributes['action'].value )){ const validations = $(ev.target).data('form').options.validations; validations.push(validation); form = ev.target; } jQuery['check_' + validation.name] = function(post_text, opts){ if(form && form.message && form.message_mode){ if(form.message_mode.value == 'visual' && (!/^\[spoiler\]/.test(post_text) && (!/^\<div /.test(post_text.trim()) && !/data\-tag=(['"]*)spoiler\1/.test(post_text.split(">")[0])))){ form.message.value = `[spoiler]${form.message.value}[/spoiler]`; }else if(form.message_mode.value == 'bbcode' && !/^\[spoiler\]/.test(post_text)){ form.message.value = `[spoiler]${form.message.value}[/spoiler]`; } } return true; } } }) </script>
The usual caveats apply: it won't work on mobile or if javascript has been disabled or an error condition prevents code execution. Let me know if you encounter any odd behavior that I did not catch. Updates:- A simple malformed BBCode tag can render this code ineffective, but as with all JavaScript codes, vulnerabilities are part of the package.
|
|