Turnip Exchange Filter

Filter by price

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Turnip Exchange Filter
// @namespace    dkt.turnip.exchange.filter
// @version      0.0.1
// @description  Filter by price
// @author       You
// @match        https://turnip.exchange/islands
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const priceInput = document.createElement('input');
    priceInput.value = 500;
    priceInput.type = 'number';
    priceInput.style = 'position:fixed;top:10px;left:10px;width:100px;height:35px;line-height:35px;font-size:20px;background-color:white;border:1px solid pink;border-radius:5px;color:black;padding:5px;';
    document.body.append(priceInput);

    const savedPrice = localStorage.getItem('FILTER_PRICE');
    if (!savedPrice) {
        localStorage.setItem('FILTER_PRICE', priceInput.value);
    } else {
        priceInput.value = savedPrice;
    }

    priceInput.addEventListener('change', () => {
        localStorage.setItem('FILTER_PRICE', priceInput.value);
    });

    let ifReplaced = false;
    let checker = setInterval(() => {
        if (ifReplaced) {
            clearInterval(checker);
            return;
        }
        const cards = document.querySelectorAll('div[data-turnip-code]');
        if (cards.length > 5) {
            cards.forEach((cardElement) => {
                const priceElement = cardElement.querySelector('div > div > img + p');
                if (parseInt(priceElement.textContent.split(' ')[0]) < parseInt(priceInput.value)) {
                    cardElement.remove();
                }
            });
            ifReplaced = true;
        }
    }, 100);
})();