From badaca48b8b137c0a8ec28511603dd4e9095b38e Mon Sep 17 00:00:00 2001 From: sangafabrice <69244030+sangafabrice@users.noreply.github.com> Date: Fri, 11 Jul 2025 13:28:05 +0100 Subject: [PATCH] init snippets --- Add New Languages.js | 54 +++++++++++++++++++++++++++++ Add and Hide Waiting For Refresh.js | 41 ++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Add New Languages.js create mode 100644 Add and Hide Waiting For Refresh.js diff --git a/Add New Languages.js b/Add New Languages.js new file mode 100644 index 0000000..67a561d --- /dev/null +++ b/Add New Languages.js @@ -0,0 +1,54 @@ +(function () { + const input = document.querySelector("input"); + const ul = document.querySelector("ul"); + const lis = document.querySelectorAll("li"); + const currentValue = input.value; + [ + "Bafang", + "Bulu", + "Fulfulde", + "Ghomala", + "Makaa", + "Medumba", + "Nufi", + "Nuguru", + "Yemba" + ].forEach(lang => { + const li = document.createElement("li"); + li.dataset.lang = lang.toLowerCase(); + try { + if (visibleStateCssRule) { + li.dataset.value = lang.toLowerCase(); + if (!lang.toLowerCase().includes(currentValue)) { + li.classList.add("not-found"); + } + ul.insertBefore(li, + [...lis].filter(({ dataset }) => + dataset.value.toLowerCase() > lang.toLowerCase())[0]); + } + } catch { + li.appendChild(document.createTextNode(lang)); + ul.insertBefore(li, + [...lis].filter(({ innerText }) => + innerText.toLowerCase() > lang.toLowerCase())[0]); + } + + }); + + + + const style = document.createElement("style"); + document.querySelector("head") + .appendChild(style) + .appendChild(document.createTextNode(`[data-lang*="${currentValue}"]{background-color: rgb(29, 156, 29);li:not(&)[data-lang]{background-color: rgb(240, 53, 53);}}`)) + + input.oninput = async function () { + if (this.value != currentValue) return; + await new Promise(resolve => setTimeout(resolve, 1000)); + style.innerText = `[data-lang*="${currentValue}"]{background-color: white;transition: background-color 1000ms ease}`; + await new Promise(resolve => setTimeout(resolve, 1100)); + style.remove(); + this.oninput = undefined; + } + +})(); \ No newline at end of file diff --git a/Add and Hide Waiting For Refresh.js b/Add and Hide Waiting For Refresh.js new file mode 100644 index 0000000..299ea06 --- /dev/null +++ b/Add and Hide Waiting For Refresh.js @@ -0,0 +1,41 @@ +(function () { + const ul = document.querySelector("ul"); + const lis = document.querySelectorAll("li"); + [ + "Bafang", + "Bulu", + "Fulfulde", + "Ghomala", + "Makaa", + "Medumba", + "Nufi", + "Nuguru", + "Yemba" + ].forEach(lang => { + const li = document.createElement("li"); + li.classList.add("not-found"); + li.dataset.lang = lang.toLowerCase(); + li.appendChild(document.createTextNode(lang)); + ul.insertBefore(li, + [...lis].filter(({ innerText }) => + innerText.toLowerCase() > lang.toLowerCase())[0]); + }); + + const input = document.querySelector("input"); + const currentValue = input.value; + const style = document.createElement("style"); + document.querySelector("head") + .appendChild(style) + .appendChild(document.createTextNode(`[data-lang*="${currentValue}"]{background-color: rgb(29, 156, 29);li:not(&)[data-lang]{background-color: rgb(240, 53, 53);}}`)) + + + input.oninput = async function () { + if (this.value != currentValue) return; + await new Promise(resolve => setTimeout(resolve, 1000)); + style.innerText = `[data-lang*="${currentValue}"]{background-color: white;transition: background-color 1000ms ease}`; + await new Promise(resolve => setTimeout(resolve, 1100)); + style.remove(); + this.oninput = undefined; + } + +})(); \ No newline at end of file