Advertisement
jcunews

shopee.vn_add_sold_count_filter.user.js

Jan 4th, 2023
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        shopee.vn add product sold count filter
  3. // @namespace   https://greasyfork.org/en/users/85671-jcunews
  4. // @version     1.0.1
  5. // @license     AGPL v3
  6. // @author      jcunews
  7. // @description Context: https://www.reddit.com/r/userscripts/comments/zynyrs/request_minimum_sold_unit_filter_on_shopee/
  8. // @match       https://shopee.vn/*
  9. // @grant       none
  10. // @run-at      document-start
  11. // ==/UserScript==
  12.  
  13. ((rx, minSold) => {
  14.   minSold = 0;
  15.   rx = /(\d+(?:,\d+)?)(k)?/;
  16.   function check(ele, a) {
  17.     if (a = ele.querySelector('.r6HknA')) {
  18.       if (a = a.textContent.match(rx)) {
  19.         a = parseFloat(a[1].replace(",", ".")) * (a[2] ? 1000 : 1)
  20.       } else a = 0;
  21.       ele.style.display = a >= minSold ? "" : "none"
  22.     }
  23.   }
  24.   (new MutationObserver(recs => {
  25.     recs.forEach(rec => {
  26.       rec.addedNodes.forEach((node, a) => {
  27.         if (node.tagName) {
  28.           if (!window.soldFilter && (a = document.querySelector('.shopee-filter-panel>button'))) {
  29.             a.previousElementSibling.insertAdjacentHTML("beforebegin", `
  30. <div id="soldFilter" class="shopee-filter-group ">
  31.   <div class="shopee-filter-group__header">Minimum Sold</div>
  32.   <div class="shopee-filter-group__body">
  33.     <div><input id="soldFilterInp" type="number" min="0" value="0"></div>
  34.   </div>
  35.   <button style="background-color:rgb(238,77,45)" class="shopee-button-solid shopee-button-solid--primary hdzZKE">Apply</button>
  36. </div>`);
  37.             soldFilter.lastElementChild.onclick = () => {
  38.               soldFilterInp.value = soldFilterInp.value.replace(/[^0-9]/g, "");
  39.               if (isNaN(soldFilterInp.valueAsNumber)) soldFilterInp.valueAsNumber = 0;
  40.               minSold = soldFilterInp.valueAsNumber;
  41.               document.querySelectorAll('.shopee-search-item-result__item').forEach(check)
  42.             };
  43.             a.addEventListener("click", () => soldFilterInp.valueAsNumber = minSold = 0, true)
  44.           }
  45.           if (a = node.closest('.shopee-search-item-result__item')) {
  46.             check(a)
  47.           } else node.querySelectorAll('.shopee-search-item-result__item').forEach(check)
  48.         }
  49.       })
  50.     })
  51.   })).observe(document, {childList: true, subtree: true})
  52. })()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement