Advertisement
Guest User

aaa

a guest
Dec 9th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // ==UserScript==
  2. // @name MTX Sort
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description Sort MTX by price on Path of Exile's Main Site.
  6. // @author You
  7. // @match https://www.pathofexile.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // 1. find all blocks
  15. const container = document.querySelector('.shopItems')
  16. const alldivs = Array.from(container.querySelectorAll('.shopItem, .shopItemPackage'));
  17.  
  18. // 2. sort them
  19. alldivs.sort((a, b)=>{
  20. let price_a = Number(a.querySelector('.price').textContent);
  21. let price_b = Number(b.querySelector('.price').textContent);
  22. return (price_a < price_b) ? -1 : 1;
  23. });
  24.  
  25. alldivs.forEach((item, i)=>{
  26. // 3. update classes
  27. item.classList.remove('right-align');
  28. if (i % 2 == 1) {
  29. item.classList.add('right-align');
  30. }
  31.  
  32. // 4. update DOM
  33. container.appendChild(item);
  34. });
  35. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement