Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ function checkVersionFilter() {
}
}

function normalizeTitleSearchText(value) {
return value.replaceAll(/[-\/&()]/gi, " ").replaceAll(/( ){2,}/gi, " ").trim();
}

function searchNow(value = "") {
if (value !== "") // Update searchBar value
searchBar.value = value;
Expand Down Expand Up @@ -249,13 +253,16 @@ function searchNow(value = "") {

searchValue = searchValue.replaceAll(/( ){2,}/gi, " ") // Filter duplicate spaces
searchValue = searchValue.replaceAll(/[^a-zA-Z0-9 #_-]/gi, ""); // Filter none alphabet and digits to avoid regex errors (#_-) used for hash/id searching
let titleSearchValue = normalizeTitleSearchText(searchValue);

allElements.forEach((e) => {
let patterns = document.querySelectorAll(`#${e.id} .item-details .skript-code-block`);
for (let i = 0; i < patterns.length; i++) { // Search in the patterns for better results
let pattern = patterns[i];
let regex = new RegExp(searchValue, "gi")
let name = document.querySelectorAll(`#${e.id} .item-title h1`)[0].textContent // Syntax Name
let titleRegex = new RegExp(titleSearchValue, "gi")
let normalizedName = normalizeTitleSearchText(name)
let desc = document.querySelectorAll(`#${e.id} .item-description`)[0].textContent // Syntax Desc
let keywords = e.getAttribute("data-keywords")
let id = e.id // Syntax ID
Expand Down Expand Up @@ -305,7 +312,7 @@ function searchNow(value = "") {
if (filterNewFound && versionFound && filterTypeFound)
filtersFound = true

if ((regex.test(pattern.textContent.replaceAll("[ ]", " ")) || regex.test(name) ||
if ((regex.test(pattern.textContent.replaceAll("[ ]", " ")) || titleRegex.test(normalizedName) ||
regex.test(desc) || regex.test(keywords) || "#" + id.toLowerCase() == searchValue.toLowerCase() || searchValue == "") && filtersFound) { // Replacing '[ ]' will improve some searching cases such as 'off[ ]hand'
pass = true
break; // Performance
Expand Down Expand Up @@ -427,4 +434,4 @@ if (cookiesAccept && cookiesDeny) {
cookiesBar.remove();
});
}
// Cookies Accecpt </>
// Cookies Accecpt </>
11 changes: 9 additions & 2 deletions docs/templates/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ function checkVersionFilter() {
}
}

function normalizeTitleSearchText(value) {
return value.replaceAll(/[-\/&()]/gi, " ").replaceAll(/( ){2,}/gi, " ").trim();
}

function searchNow(value = "") {
if (value !== "") // Update searchBar value
searchBar.value = value;
Expand Down Expand Up @@ -249,13 +253,16 @@ function searchNow(value = "") {

searchValue = searchValue.replaceAll(/( ){2,}/gi, " ") // Filter duplicate spaces
searchValue = searchValue.replaceAll(/[^a-zA-Z0-9 #_-]/gi, ""); // Filter none alphabet and digits to avoid regex errors (#_-) used for hash/id searching
let titleSearchValue = normalizeTitleSearchText(searchValue);

allElements.forEach((e) => {
let patterns = document.querySelectorAll(`#${e.id} .item-details .skript-code-block`);
for (let i = 0; i < patterns.length; i++) { // Search in the patterns for better results
let pattern = patterns[i];
let regex = new RegExp(searchValue, "gi")
let name = document.querySelectorAll(`#${e.id} .item-title h1`)[0].textContent // Syntax Name
let titleRegex = new RegExp(titleSearchValue, "gi")
let normalizedName = normalizeTitleSearchText(name)
let desc = document.querySelectorAll(`#${e.id} .item-description`)[0].textContent // Syntax Desc
let keywords = e.getAttribute("data-keywords")
let id = e.id // Syntax ID
Expand Down Expand Up @@ -305,7 +312,7 @@ function searchNow(value = "") {
if (filterNewFound && versionFound && filterTypeFound)
filtersFound = true

if ((regex.test(pattern.textContent.replaceAll("[ ]", " ")) || regex.test(name) ||
if ((regex.test(pattern.textContent.replaceAll("[ ]", " ")) || titleRegex.test(normalizedName) ||
regex.test(desc) || regex.test(keywords) || "#" + id.toLowerCase() == searchValue.toLowerCase() || searchValue == "") && filtersFound) { // Replacing '[ ]' will improve some searching cases such as 'off[ ]hand'
pass = true
break; // Performance
Expand Down Expand Up @@ -427,4 +434,4 @@ if (cookiesAccept && cookiesDeny) {
cookiesBar.remove();
});
}
// Cookies Accecpt </>
// Cookies Accecpt </>