From c78d62ecbf17e5983355b7c47f5118fe6e8d60ca Mon Sep 17 00:00:00 2001 From: m417z <4129781+m417z@users.noreply.github.com> Date: Wed, 4 May 2022 23:38:51 +0300 Subject: [PATCH] Minor fixes --- quote-comments.js | 36 ++++++++++++++++-------------------- quote-comments.php | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/quote-comments.js b/quote-comments.js index 33138f3..bb7d3b0 100755 --- a/quote-comments.js +++ b/quote-comments.js @@ -5,23 +5,14 @@ function jsEncode(str){ - // ugly hack - str = " " + str; - - var aStr = str.split(''), i = aStr.length, aRet = []; + str = str.toString(); + str = str.replace(/&/g, '&'); + str = str.replace(//g, '>'); + str = str.replace(/'/g, '''); + str = str.replace(/"/g, '"'); + + return str; - while (--i) { - var iC = aStr[i].charCodeAt(); - - if (iC < 65 || iC > 127 || (iC>90 && iC<97)) { - aRet.push('&#'+iC+';'); - } else { - aRet.push(aStr[i]); - } - } - - return aRet.reverse().join(''); - } @@ -50,10 +41,11 @@ function quote(postid, author, commentarea, commentID, mce) { return true; } + posttext = posttext.toString(); + if (posttext=='') { // quoting entire comment - // quoteing the entire thing - var selection = false; + // quoting the entire thing var commentID = commentID.split("div-comment-")[1]; // quote entire comment as html @@ -94,6 +86,10 @@ function quote(postid, author, commentarea, commentID, mce) { } + // trim + var posttext = posttext.replace(/^\s+/, ""); + var posttext = posttext.replace(/\s+$/, ""); + // build quote if (author) { @@ -104,7 +100,7 @@ function quote(postid, author, commentarea, commentID, mce) { } else { - var quote='\n
\n\n'+posttext+'
\n'; + var quote='
\n'+posttext+'\n
\n'; } @@ -141,7 +137,7 @@ function inlinereply(postid, author, commentarea, commentID, mce) { author = jsEncode(author); // build quote - var quote='\n'+unescape(author)+', \n\n'; + var quote=''+unescape(author)+', \n\n'; // send quoted content diff --git a/quote-comments.php b/quote-comments.php index cc90181..4115141 100755 --- a/quote-comments.php +++ b/quote-comments.php @@ -192,7 +192,7 @@ function add_quote_button_filter($output) { } else { - return($output . $button); + return $output; }