376.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function getZL(ele) {
  2. if (!ele.querySelector('.zy-meli-card-wrap') || !ele.querySelector('.zy-meli-card-wrap').shadowRoot) {
  3. return -1
  4. }
  5. let temp = ele.querySelector('.zy-meli-card-wrap').shadowRoot.querySelectorAll('.meli-card-info-row .meli-card-info-value')[1].innerText
  6. temp = temp.replace('g', '')
  7. if (temp == '-') return -1
  8. if (temp == '') return -1
  9. return parseInt(temp)
  10. }
  11. function orderList () {
  12. let domList = []
  13. document.querySelectorAll('.ui-search-layout__item').forEach(element => {
  14. domList.push(element)
  15. });
  16. domList = domList.sort((a, b) => getZL(b) - getZL(a));
  17. domList.forEach(element => {
  18. console.log(getZL(element))
  19. });
  20. let tempDom = ``
  21. domList.forEach(element => {
  22. tempDom += element.outerHTML
  23. });
  24. document.querySelector('.ui-search-layout.ui-search-layout--grid').innerHTML = tempDom
  25. }
  26. function orderList2 () {
  27. let domList = []
  28. document.querySelectorAll('.ui-search-layout__item').forEach(element => {
  29. domList.push(element)
  30. });
  31. domList = domList.sort((a, b) => getZL(a) - getZL(b));
  32. domList.forEach(element => {
  33. console.log(getZL(element))
  34. });
  35. let tempDom = ``
  36. domList.forEach(element => {
  37. tempDom += element.outerHTML
  38. });
  39. document.querySelector('.ui-search-layout.ui-search-layout--grid').innerHTML = tempDom
  40. }
  41. window.pugeCreated = function (el) {
  42. el.innerHTML = '<div class="owo"><div class="owo button" id="cddx" >按重量大->小</div><div class="owo button" id="cxdd" >按重量小->大</div></div>'
  43. setTimeout(() => {
  44. window.cddx.onclick = function () {
  45. orderList()
  46. }
  47. window.cxdd.onclick = function () {
  48. orderList2()
  49. }
  50. }, 1000);
  51. }