From 72f38933c2af830d6d6ad4dae3735cdb4ddecae6 Mon Sep 17 00:00:00 2001 From: ben2613 Date: Thu, 28 Jul 2022 00:45:31 +0100 Subject: [PATCH] Fix mobile browser hang issue when auto-reload by reducing DOM modification in forloop --- js/auto-reload.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/js/auto-reload.js b/js/auto-reload.js index d015dfc1..0a38f9b2 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -144,19 +144,26 @@ $(document).ready(function(){ url: document.location, success: function(data) { var loaded_posts = 0; // the number of new posts loaded in this update + var elementsToAppend = []; + var elementsToTriggerNewpostEvent = []; $(data).find('div.post.reply').each(function() { var id = $(this).attr('id'); if($('#' + id).length == 0) { if (!new_posts) { first_new_post = this; } - $(this).insertAfter($('div.post:last').next()).after('
'); new_posts++; loaded_posts++; - $(document).trigger('new_post', this); - recheck_activated(); + elementsToAppend.push($(this)); + elementsToAppend.push($('
')); + elementsToTriggerNewpostEvent.push(this); } }); + $('div.post:last').next().after(elementsToAppend); + recheck_activated(); + elementsToTriggerNewpostEvent.forEach(function(ele){ + $(document).trigger('new_post', ele); + }); time_loaded = Date.now(); // interop with watch.js