Skip to content

Instantly share code, notes, and snippets.

@jaredschnelle
Last active April 7, 2025 12:31
PoE 2 Trade Site Filter by Explicit Mods Tampermonkey
// ==UserScript==
// @name POE Trade Filter
// @namespace http://tampermonkey.net/
// @version 2025-01-06
// @description Find hidden .. jewels .. in poe trade search
// @author @schnelle on twitter
// @match https://www.pathofexile.com/trade2/search/poe2/Standard
// @match https://www.pathofexile.com/trade2/search/poe2/Standard/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=pathofexile.com
// @grant none
// ==/UserScript==
var filters = [];
var numSearchResultsFiltered = 0;
var numMatches = 0;
var autoLoad = false;
$(document).ready(function() {
startFilteringResults();
updateLabels();
});
var refreshDataTimer = null;
function startFilteringResults() {
var $parentContainer = $("<div class='yeti-filter-box' style='width: 500px;height: 40px;position: fixed; top: 25px; right: 10px;justify-content: space-around;display: flex;flex-direction: row;margin: 10px auto;border: solid 1px #a0a0d0;background-color: #111;'>");
var $contentContainer = $("<div style='display: flex;flex-direction: column;width: 100%;padding: 2px 6px;align-items: center;'>");
var $filtersContainer = $("<div class='filters-container' style='display: flex;flex-direction: column;width: 100%;padding: 2px 6px;align-items: center;'>");
var $infoContainer = $("<div style='display: flex;flex-direction: row;justify-content: space-between;width: 100%;padding: 2px 8px;align-items: center;'>");
var $infoLabel1 = $("<div class='filter-label-1' style='font-family: FontinSmallcaps;font-size: 14.3px;'>");
var $infoLabel2 = $("<div class='filter-label-2' style='font-family: FontinSmallcaps;font-size: 14.3px;'>");
var $autoLoadButton = $("<div class='auto-load-button' style='font-family: sans-serif;font-size: 10px;border: solid 1px #64cf64;color: #ffffff !important;padding: 3px 6px;background-color: #309630;user-select: none;'>");
initAutoLoadButton($autoLoadButton, autoLoad);
var $addFilterButton = $("<div class='auto-load-button' style='font-family: sans-serif;font-size: 10px;border: solid 1px #4c4c7d;color: #ffffff !important;padding: 3px 6px;background-color: #0f304d;user-select: none;'>");
initAddFilterButton($addFilterButton);
$infoContainer.append($infoLabel1);
$infoContainer.append($autoLoadButton);
$infoContainer.append($addFilterButton);
$infoContainer.append($infoLabel2);
$contentContainer.append($filtersContainer);
$contentContainer.append($infoContainer);
$parentContainer.append($contentContainer);
$('body').append($parentContainer);
addFilterOption();
}
function addFilterOption() {
//Create the filter in js
var filter = {
"explicit1": '',
"explicit2": ''};
filters.push(filter);
var thisFilterIndex = filters.length-1;
var totalFiltersCount = thisFilterIndex + 1;
var $filtersContainer = $('.filters-container');
//Add it to the UI
var $filterContainer = $("<div style='display: flex;flex-direction: row;width: 100%;padding: 2px 6px;align-items: center;'>");
var $filterLabel = $("<div class='filter-title' style='font-family: FontinSmallcaps;font-size: 14.3px;'>").text("Filter #" + totalFiltersCount);
var $filterInput1 = $("<input class='form-control text' style='width: 180px;' placeholder='Explicit #1'>");
var $filterInput2 = $("<input class='form-control text' style='width: 180px;' placeholder='Explicit #2'>");
$filterContainer.append($filterLabel);
$filterContainer.append($filterInput1);
$filterContainer.append($filterInput2);
$filtersContainer.append($filterContainer);
//When the textbox value changes, update the global variable holding all the filters
$filterInput1.on('input',function(e){
filters[thisFilterIndex].explicit1 = $(this).val().toUpperCase();
applyFilter();
});
$filterInput2.on('input',function(e){
filters[thisFilterIndex].explicit2 = $(this).val().toUpperCase();
applyFilter();
});
var filterBoxHeight = 40 + totalFiltersCount*36;
$('.yeti-filter-box').css("height", filterBoxHeight + "px");
}
function applyFilter() {
//Default page load, nothing in the search boxes so act like normal and do nothing.
if(filters.length == 1 && filters[0].explicit1 == '' && filters[0].explicit2 == '') {
$('.resultset .row').show();
clearTimeout(refreshDataTimer);
return;
}
numSearchResultsFiltered = $('.resultset [class="row"]').length;
numMatches = 0;
//Apply the filter
$('.resultset .row').each(function() {
var $tradeItem = $(this);
//Hide this item, if there are modifiers that match our search, they will 'show' the parent item and undo this hide
$tradeItem.hide();
var didMatch = false;
for(let i = 0; i < filters.length && didMatch == false; i++) {
var filter = filters[i];
var filter1Match = false;
var filter2Match = false;
if($('.search-left input').val() == 'Megalomaniac Diamond')
{
$tradeItem.find('.enchantMod').each(function() {
$(this).children().each(function() {
var modText = $(this).text();
if(modText.toUpperCase().includes(filter.explicit1))
filter1Match = true;
if(modText.toUpperCase().includes(filter.explicit2))
filter2Match = true;
});
});
}
else
{
$tradeItem.find('.explicitMod').each(function() {
$(this).children().each(function() {
var modText = $(this).text();
if(modText.toUpperCase().includes(filter.explicit1))
filter1Match = true;
if(modText.toUpperCase().includes(filter.explicit2))
filter2Match = true;
});
});
}
if(filter.explicit1.length > 0) {
if(filter.explicit2.length > 0) {
if(filter1Match && filter2Match) {
$tradeItem.show();
didMatch = true;
numMatches++;
}
}
else {
if(filter1Match){
$tradeItem.show();
didMatch = true;
numMatches++;
}
}
}
else if(filter.explicit2.length > 0) {
if(filter2Match){
$tradeItem.show();
didMatch = true;
numMatches++;
}
}
}
});
//Set a timeout to check if we have new data in from the server from loading manually, activate live search, or scrolling
clearTimeout(refreshDataTimer);
refreshDataTimer = setTimeout(scanForNewItems, 1000);
//Make sure we can still see the "show more" button at the bottom
if($('.resultset .row.controls').length) {
$('.resultset .row.controls').show();
if(autoLoad)
$('.load-more-btn').trigger("click");
}
updateLabels();
}
function updateLabels() {
$('.filter-label-1').text('Filtering ' + numSearchResultsFiltered + ' results');
$('.filter-label-2').text(numMatches + ' matched');
}
function scanForNewItems() {
var numSearchResults = $('.resultset .row').length;
//We have new data
if(numSearchResults != numSearchResultsFiltered) {
applyFilter();
}
else {
clearTimeout(refreshDataTimer);
refreshDataTimer = setTimeout(scanForNewItems, 1000);
}
}
function initAutoLoadButton($autoLoadButton, state) {
$autoLoadButton.text("Auto Load");
$autoLoadButton.hover(function() {
$(this).css("cursor", "pointer");
});
if(state) {
$autoLoadButton.css({
"border": "solid 1px #64cf64",
"color": "#ffffff !important",
"background-color": "#309630"
});
}
else {
$autoLoadButton.css({
"border": "solid 1px #4f4e4e",
"color": "#aaaaaa !important",
"background-color": "#222222"
});
}
$autoLoadButton.click(function() {
autoLoad = !autoLoad;
if(autoLoad) {
$(this).css({
"border": "solid 1px #64cf64",
"color": "#ffffff !important",
"background-color": "#309630"
});
}
else {
$(this).css({
"border": "solid 1px #4f4e4e",
"color": "#aaaaaa !important",
"background-color": "#222222"
});
}
});
}
function initAddFilterButton($addFilterButton) {
$addFilterButton.text("Add Filter");
$addFilterButton.hover(function() {
$(this).css("cursor", "pointer");
});
$addFilterButton.click(function() {
addFilterOption();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment