From 9a5b2c93856597a0ac3eb5d69126f1dfe89e7dbc Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Thu, 11 Aug 2022 12:01:53 +0200 Subject: [PATCH] remove duplicate dms --- js/dms.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/dms.js b/js/dms.js index b4c1700..45f78f0 100644 --- a/js/dms.js +++ b/js/dms.js @@ -337,6 +337,18 @@ function switchChannel(channelname) { socket.send(JSON.stringify({"id":"switchChannel","data":channelname})) } +function removeDuplicates(a) { + let prims = {"boolean":{}, "number":{}, "string":{}}, objs = []; + + return a.filter(function(item) { + let type = typeof item; + if(type in prims) + return prims[type].hasOwnProperty(item) ? false : (prims[type][item] = true); + else + return objs.indexOf(item) >= 0 ? false : objs.push(item); + }); +} + async function loadChannels() { // @@ -352,6 +364,8 @@ async function loadChannels() { } } + channels = removeDuplicates(channels) + let tab = document.getElementById("channelTab") tab.innerHTML = "" for (let i = 0; i < channels.length; i++) {