From 5f2b258a96b9dbdd22058544bcdf134c1f8b366e Mon Sep 17 00:00:00 2001 From: Benzo <102178921+Benzo00@users.noreply.github.com> Date: Thu, 9 Jun 2022 01:57:53 +0200 Subject: [PATCH] fix(notify) support color codes --- [esx]/esx_notify/Notify.lua | 4 +- [esx]/esx_notify/nui/css/style.css | 3 + [esx]/esx_notify/nui/index.html | 7 + [esx]/esx_notify/nui/js/script.js | 360 ++++++++++++++++++++++++++++- 4 files changed, 372 insertions(+), 2 deletions(-) diff --git a/[esx]/esx_notify/Notify.lua b/[esx]/esx_notify/Notify.lua index 27c7956e..50007c32 100644 --- a/[esx]/esx_notify/Notify.lua +++ b/[esx]/esx_notify/Notify.lua @@ -6,6 +6,8 @@ local function Notify(type, length, message) })) end + + + exports('Notify', Notify) RegisterNetEvent("ESX:Notify", Notify) - diff --git a/[esx]/esx_notify/nui/css/style.css b/[esx]/esx_notify/nui/css/style.css index 3eacd92a..05469ab9 100644 --- a/[esx]/esx_notify/nui/css/style.css +++ b/[esx]/esx_notify/nui/css/style.css @@ -32,6 +32,9 @@ body { } .success { border-left: 5px solid rgb(33, 223, 15) !important; +} +.custom { + } .error { border-left: 5px solid rgb(231, 35, 28) !important; diff --git a/[esx]/esx_notify/nui/index.html b/[esx]/esx_notify/nui/index.html index 58817fe1..65579325 100644 --- a/[esx]/esx_notify/nui/index.html +++ b/[esx]/esx_notify/nui/index.html @@ -7,6 +7,13 @@ +
+
+ +

+
+
+
diff --git a/[esx]/esx_notify/nui/js/script.js b/[esx]/esx_notify/nui/js/script.js index 9bacc374..eb734ef5 100644 --- a/[esx]/esx_notify/nui/js/script.js +++ b/[esx]/esx_notify/nui/js/script.js @@ -1,23 +1,381 @@ const w = window const doc = document + $(function () { w.addEventListener('message', function(e) { - $(".text").text(e.data.message) + $(".text").text('') const start = new Date() const max = e.data.length const val = Math.floor(max/100) let current = "" + let blackc = {'color': '#000'}; + let redc = {'color': '#F00'}; + let greenc = {'color': '#0F0'}; + let bluec = {'color': '#00F'}; + let yellowc = {'color': '#ff0'}; + let greyc = {'color': '#808080'}; + let darkgreyc = {'color': '#a9a9a9'}; + let orangec = {'color': '#FFA500'}; + let purplec = {'color': '#800080'}; + let whitec = {'color': '#FFF'}; + if (e.data.type === "info") { doc.getElementById("notifyInfo").style.display = "block"; + let finalarr = [] + + + + + var arr = e.data.message.split("~") + for (let i = 0; i < arr.length; i++) { + let arr1 = arr[i] + + let redTrue = arr1.startsWith("r") + let greenTrue = arr1.startsWith("g") + let whiteTrue = arr1.startsWith("w") + let blackTrue = arr1.startsWith("u") + let blueTrue = arr1.startsWith("b") + let yellowTrue = arr1.startsWith("y") + let greyTrue = arr1.startsWith("c") + let darkgreyTrue = arr1.startsWith("m") + let orangeTrue = arr1.startsWith("o") + let purpleTrue = arr1.startsWith("p") + + if (i == 0) { + if (arr1.startsWith("~")) { + + } else { + let arr3 = $('' + arr[i] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } + } + + if (redTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(redc) + + finalarr.push(arr3) + } else if (greenTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greenc) + + finalarr.push(arr3) + } else if (whiteTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } else if (blackTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(blackc) + + finalarr.push(arr3) + } else if (blueTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(bluec) + + finalarr.push(arr3) + } else if (yellowTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(yellowc) + + finalarr.push(arr3) + } else if (greyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greyc) + + finalarr.push(arr3) + } else if (darkgreyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(darkgreyc) + + finalarr.push(arr3) + } else if (orangeTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(orangec) + + finalarr.push(arr3) + } else if (purpleTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(purplec) + finalarr.push(arr3) + } + + + } + $(".text").append(finalarr); + finalarr = [] RequestAnimUpdate() current = "notifyInfo" } else if (e.data.type === "error") { doc.getElementById("notifyError").style.display = "block"; + let finalarr = [] + + + + + var arr = e.data.message.split("~") + for (let i = 0; i < arr.length; i++) { + let arr1 = arr[i] + + let redTrue = arr1.startsWith("r") + let greenTrue = arr1.startsWith("g") + let whiteTrue = arr1.startsWith("w") + let blackTrue = arr1.startsWith("u") + let blueTrue = arr1.startsWith("b") + let yellowTrue = arr1.startsWith("y") + let greyTrue = arr1.startsWith("c") + let darkgreyTrue = arr1.startsWith("m") + let orangeTrue = arr1.startsWith("o") + let purpleTrue = arr1.startsWith("p") + + if (i == 0) { + if (arr1.startsWith("~")) { + + } else { + let arr3 = $('' + arr[i] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } + } + + if (redTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(redc) + + finalarr.push(arr3) + } else if (greenTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greenc) + + finalarr.push(arr3) + } else if (whiteTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } else if (blackTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(blackc) + + finalarr.push(arr3) + } else if (blueTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(bluec) + + finalarr.push(arr3) + } else if (yellowTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(yellowc) + + finalarr.push(arr3) + } else if (greyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greyc) + + finalarr.push(arr3) + } else if (darkgreyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(darkgreyc) + + finalarr.push(arr3) + } else if (orangeTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(orangec) + + finalarr.push(arr3) + } else if (purpleTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(purplec) + finalarr.push(arr3) + } + + + } + $(".text").append(finalarr); RequestAnimUpdate() current = "notifyError" } else if (e.data.type === "success") { doc.getElementById("notifySuccess").style.display = "block"; + let finalarr = [] + + + + + var arr = e.data.message.split("~") + for (let i = 0; i < arr.length; i++) { + let arr1 = arr[i] + + let redTrue = arr1.startsWith("r") + let greenTrue = arr1.startsWith("g") + let whiteTrue = arr1.startsWith("w") + let blackTrue = arr1.startsWith("u") + let blueTrue = arr1.startsWith("b") + let yellowTrue = arr1.startsWith("y") + let greyTrue = arr1.startsWith("c") + let darkgreyTrue = arr1.startsWith("m") + let orangeTrue = arr1.startsWith("o") + let purpleTrue = arr1.startsWith("p") + + if (i == 0) { + if (arr1.startsWith("~")) { + + } else { + let arr3 = $('' + arr[i] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } + } + + if (redTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(redc) + + finalarr.push(arr3) + } else if (greenTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greenc) + + finalarr.push(arr3) + } else if (whiteTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(whitec) + + finalarr.push(arr3) + } else if (blackTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(blackc) + + finalarr.push(arr3) + } else if (blueTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(bluec) + + finalarr.push(arr3) + } else if (yellowTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(yellowc) + + finalarr.push(arr3) + } else if (greyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(greyc) + + finalarr.push(arr3) + } else if (darkgreyTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(darkgreyc) + + finalarr.push(arr3) + } else if (orangeTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(orangec) + + finalarr.push(arr3) + } else if (purpleTrue) { + x = i + 1 + + + let arr3 = $('' + arr[x] + ''); + arr3.css(purplec) + finalarr.push(arr3) + } + + + } + $(".text").append(finalarr); RequestAnimUpdate() current = "notifySuccess" }