From 027ba80e8578bd6a36a8b39eb8756590982a30a7 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 19 Mar 2023 15:46:34 +0200 Subject: [PATCH] order popup emoji modal results by usage count --- files/assets/js/emoji_modal.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index daf2bc7f9..cb0f54233 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -38,6 +38,8 @@ const favorite_emojis = JSON.parse(localStorage.getItem("favorite_emojis")) || { /** Associative array of all the emojis' DOM */ let emojiDOMs = {}; +let globalEmojis; + const EMOIJ_SEARCH_ENGINE_MIN_INTERVAL = 350; let emojiSearcher = { working: false, @@ -141,11 +143,13 @@ const emojisSearchDictionary = { const emojiRequest = new XMLHttpRequest(); emojiRequest.open("GET", '/emojis.csv'); emojiRequest.setRequestHeader('xhr', 'xhr'); -emojiRequest.onload = async (e) => { +emojiRequest.onload = async () => { let emojis = JSON.parse(emojiRequest.response); if(! (emojis instanceof Array )) throw new TypeError("[EMOJI DIALOG] rDrama's server should have sent a JSON-coded Array!"); + globalEmojis = emojis.map(i => i.name); + let classes = new Set(); const bussyDOM = document.createElement("div"); @@ -430,7 +434,11 @@ function update_speed_emoji_modal(event) speed_carot_modal.style.top = modal_pos.y + box_coords.y + 14 + "px"; // Do the search (and do something with it) - populate_speed_emoji_modal(emojisSearchDictionary.completeSearch(current_word.substr(1).replace(/#/g, "").replace(/!/g, "")), event.target); + const resultSet = emojisSearchDictionary.completeSearch(current_word.substr(1).replace(/#/g, "").replace(/!/g, "")) + + const found = globalEmojis.filter(value => resultSet.has(value)); + + populate_speed_emoji_modal(found, event.target); } else {