Turnip Exchange Filter

Filter by price

  1. // ==UserScript==
  2. // @name Turnip Exchange Filter
  3. // @namespace dkt.turnip.exchange.filter
  4. // @version 0.0.1
  5. // @description Filter by price
  6. // @author You
  7. // @match https://turnip.exchange/islands
  8. // @run-at document-end
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const priceInput = document.createElement('input');
  15. priceInput.value = 500;
  16. priceInput.type = 'number';
  17. 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;';
  18. document.body.append(priceInput);
  19.  
  20. const savedPrice = localStorage.getItem('FILTER_PRICE');
  21. if (!savedPrice) {
  22. localStorage.setItem('FILTER_PRICE', priceInput.value);
  23. } else {
  24. priceInput.value = savedPrice;
  25. }
  26.  
  27. priceInput.addEventListener('change', () => {
  28. localStorage.setItem('FILTER_PRICE', priceInput.value);
  29. });
  30.  
  31. let ifReplaced = false;
  32. let checker = setInterval(() => {
  33. if (ifReplaced) {
  34. clearInterval(checker);
  35. return;
  36. }
  37. const cards = document.querySelectorAll('div[data-turnip-code]');
  38. if (cards.length > 5) {
  39. cards.forEach((cardElement) => {
  40. const priceElement = cardElement.querySelector('div > div > img + p');
  41. if (parseInt(priceElement.textContent.split(' ')[0]) < parseInt(priceInput.value)) {
  42. cardElement.remove();
  43. }
  44. });
  45. ifReplaced = true;
  46. }
  47. }, 100);
  48. })();