// Execute the script once the document is ready jQuery(document).ready(function(){ // List of namespaces to apply the script to var namespaces = ["namespace:page"]; // Restrict to a specific namespace if (namespaces.indexOf(JSINFO['id']) > -1) { // Check if "?do=" & "&do=" is present in the URL if (window.location.search.indexOf("?do=") === -1 && window.location.search.indexOf("&do=") === -1) { // Find all the texteareas and Replace " \ " with newlines jQuery(this).find('textarea').each(function() { // Check if the textarea is visible if (jQuery(this).is(":visible")) { // Replace " \ " with newlines jQuery(this).val(jQuery(this).val().replace(/ \\ /gm, "\n")); } }); // Replace default form submission with custom function jQuery("form").on("submit", function(event) { // Prevent the form from submitting immediately event.preventDefault(); // Find all the texteareas and replace newlines with " \ " jQuery(this).find('textarea').each(function() { // Check if the textarea is visible if (jQuery(this).is(":visible")) { // Replace newlines with " \ " jQuery(this).val(jQuery(this).val().replace(/\n/gm, ' \\ ')); } }); // After running the function, manually trigger the form submission this.submit(); }); } } });