From 8e362bec245ecb2c8007d59b1843a0c43a6f862f Mon Sep 17 00:00:00 2001 From: Pat O'Brien <3484775+poblabs@users.noreply.github.com> Date: Thu, 3 Oct 2019 09:54:16 -0400 Subject: [PATCH] Do not add duplicate headers, and clear table for append Instead of appending the API results non-stop, we clear the table first so that it's fresh data loaded into the table. In addition, I added a class to the "To" `tr` and jQuery will look for this class. If it doesn't exist then it'll add that `tr`. Otherwise it won't continue to stack it. Fixes https://github.com/HaschekSolutions/opentrashmail/issues/2 --- web/js/opentrashmail.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/js/opentrashmail.js b/web/js/opentrashmail.js index 4694fdc..542009b 100644 --- a/web/js/opentrashmail.js +++ b/web/js/opentrashmail.js @@ -91,9 +91,14 @@ function updateEmailTable() { clearInterval(timer); admin = true; - $('#tableheader').children(':eq(1)').after('To'); + // Do not add the To header if one with the "to" class already exists + if ( $('#tableheader').children(':eq(2)').hasClass("to") === false ) + { + $('#tableheader').children(':eq(1)').after('To'); + } } + $("#emailtable tr").remove(); // Empty all from the table so we don't stack if(Object.keys(data.emails).length>0) for(em in data.emails) {