Turnip Exchange Filter

Filter by price

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();