// Wait for the input to appear before binding event listeners
function waitForElement(selector, callback, timeout = 5000) {
const start = Date.now();
const interval = setInterval(() => {
const element = document.querySelector(selector);
if (element) {
clearInterval(interval);
callback();
} else if (Date.now() - start > timeout) {
clearInterval(interval);
console.warn(`Element ${selector} not found within ${timeout}ms`);
}
}, 100);
}
waitForElement(".entitylist-search input.query", function () {
const input = document.querySelector(".entitylist-search input.query");
const button = document.querySelector(".entitylist-search .input-group-btn button");
if (input && button) {
console.log("Search input and button found!");
// Store original event handlers
const originalButtonHandler = button.onclick;
const originalFormHandler = input.form ? input.form.onsubmit : null;
// Override button click
button.onclick = function(e) {
// Add asterisk if needed
if (input.value && !input.value.startsWith("*")) {
input.value = "*" + input.value + "*";
}
// Call original handler if it exists
if (originalButtonHandler) {
return originalButtonHandler.call(this, e);
}
};
// Override form submission if form exists
if (input.form) {
input.form.onsubmit = function(e) {
// Add asterisk if needed
if (input.value && !input.value.startsWith("*")) {
input.value = "*" + input.value + "*";
}
// Call original handler if it exists
if (originalFormHandler) {
return originalFormHandler.call(this, e);
}
};
}
// Handle Enter key
input.addEventListener("keydown", function(e) {
if (e.key === "Enter") {
// Add asterisk if needed
if (input.value && !input.value.startsWith("*")) {
input.value = "*" + input.value + "*";
console.log("input edited");
}
// Let the event continue naturally
}
});
} else {
console.warn("Input or button still not found.");
}
});
Thanks!