Skip to content

Instantly share code, notes, and snippets.

@Krytos
Last active January 24, 2025 07:37
Show Gist options
  • Select an option

  • Save Krytos/2ae5bd9aba4dc98c2dbc98c94f26d4eb to your computer and use it in GitHub Desktop.

Select an option

Save Krytos/2ae5bd9aba4dc98c2dbc98c94f26d4eb to your computer and use it in GitHub Desktop.
When searching on pathofexile.com/trade, this addon inserts the tilde(~) before your search query. This enables fuzzy search, so you can be more lenient with your search. Start you search with a space (" ") to not use fuzzy search for this query.
// ==UserScript==
// @name PoE2 Fuzzy Search
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Prepends ~ to non-space starting queries and removes leading spaces
// @author Kevin M. (inspired by /u/posturecheck3859738 on /r/pathofexile)
// @match https://www.pathofexile.com/trade2*
// @icon https://www.google.com/s2/favicons?domain=pathofexile.com
// @downloadURL https://gist.github.com/Krytos/2ae5bd9aba4dc98c2dbc98c94f26d4eb/raw/poe2_fuzzy_search.user.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
let isProgrammaticChange = false;
function handleInputEvent(e) {
if (isProgrammaticChange) return;
const input = e.target;
let val = input.value;
// Reset session when empty
if (input.spaceSession && val === '') {
input.spaceSession = false;
return;
}
// Handle existing space session
if (input.spaceSession) return;
// Process new input
if (val.startsWith(' ')) {
const trimmed = val.trimStart();
if (trimmed.length > 0) {
isProgrammaticChange = true;
input.spaceSession = true;
input.value = trimmed;
// Update React's state
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype, "value"
).set;
nativeInputValueSetter.call(input, trimmed);
input.dispatchEvent(new Event('input', { bubbles: true }));
setTimeout(() => isProgrammaticChange = false, 0);
}
}
else if (val.length > 0 && !val.startsWith('~')) { // Modified condition
isProgrammaticChange = true;
input.value = '~' + val;
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype, "value"
).set;
nativeInputValueSetter.call(input, '~' + val);
input.dispatchEvent(new Event('input', { bubbles: true }));
setTimeout(() => isProgrammaticChange = false, 0);
}
}
// Mutation Observer setup
const observer = new MutationObserver(mutations => {
const targetInput = document.querySelector(
'div.multiselect.filter-select-mutate input.multiselect__input'
);
if (targetInput && !targetInput._modified) {
targetInput._modified = true;
targetInput.spaceSession = false;
targetInput.addEventListener('input', handleInputEvent);
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Initial setup
const existingInput = document.querySelector(
'div.multiselect.filter-select-mutate input.multiselect__input'
);
if (existingInput) {
existingInput._modified = true;
existingInput.spaceSession = false;
existingInput.addEventListener('input', handleInputEvent);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment