Greasy Fork is available in English.

Wallapop - Filtro reservados

Script para filtrar los productos reservados de Wallapop, correción y mejora del script de Kioraga

// ==UserScript==
// @name        Wallapop - Filtro reservados
// @namespace   Wallapop - Filtro reservados
// @match       https://es.wallapop.com/*
// @grant       none
// @version     1.0.0
// @author      AntonioCB14, Kioraga
// @license     MIT
// @description Script para filtrar los productos reservados de Wallapop, correción y mejora del script de Kioraga
// @icon        https://www.google.com/s2/favicons?sz=64&domain=wallapop.com
// @run-at       document-end
// @grant       GM_addStyle
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==
GM_addStyle(`
    .wallapop-button {
	    box-sizing: border-box;
	    border-top-left-radius: 25px;
	    border-top-right-radius: 25px;
	    border-bottom-right-radius: 25px;
	    border-bottom-left-radius: 25px;
	    font-family: Wallie, Helvetica;
	    overflow-x: visible;
	    overflow-y: visible;
	    text-transform: none;
	    appearance: button;
	    cursor: pointer;
	    display: flex;
	    font-weight : 400;
	    color: rgb(232, 230, 227);
	    text-align: center;
	    vertical-align: middle;
	    background-color: rgb(19, 193, 172);
	    border-top-color: transparent;
	    border-top-style: solid;
	    border-top-width: 1;
	    border-right-color: transparent;
	    border-right-style: solid;
	    border-right-width: 1;
	    border-bottom-color: transparent;
	    border-bottom-style: solid;
	    border-bottom-width: 1;
	    border-left-color: transparent;
	    border-left-style: solid;
	    border-left-width: 1;
	    border-image-outset: 0;
	    border-image-repeat: stretch;
	    border-image-slice: 100%;
	    border-image-source: none;
	    border-image-width: 1;
	    padding: 10px 15px;
	    transition-property : all, padding;
	    transition-duration : 0.2s, 0s;
	    transition-timing-function : ease-in-out, ease;
	    transition-delay : 0s, 0s;
	    align-items: center;
	    height: 40px;
	    min-width: fit-content;
      margin-left: auto;
    }

    .wallapop-button:hover {
        background-color: rgb(12, 122, 110);
    }
`);

var filtradoActivo = GM_getValue("filtradoActivo", false);

var btn = document.createElement("button");
btn.classList.add("wallapop-button");

if (filtradoActivo) {
  btn.innerHTML = "Mostrar reservados";
} else {
  btn.innerHTML = "Ocultar reservados";
}

function injectButton() {
  var filtersBar = document.querySelector("div.d-flex.ng-star-inserted");
  var lastChild = filtersBar.lastChild;
  filtersBar.insertBefore(btn, lastChild.nextSibling);
}

btn.onclick = function () {
  filtradoActivo = !filtradoActivo;
  if (filtradoActivo) {
    btn.innerHTML = "Mostrar reservados";
    GM_setValue("filtradoActivo", true);
    filtrarProductos();
  } else {
    btn.innerHTML = "Ocultar reservados";
    GM_setValue("filtradoActivo", false);
    location.reload();
  }
};

function filtrarProductos() {
  if (filtradoActivo) {
    var productos = document.querySelectorAll(
      "a.ItemCardList__item.ng-star-inserted"
    );
    productos.forEach(function (anuncio) {
      if (anuncio.querySelector('div[class*="ItemCard__badge"]')) {
        var slotDiv = anuncio.querySelector("div.ItemCardList__slot");
        if (slotDiv) {
          slotDiv.remove();
        }
        anuncio.remove();
      }
    });
  }
}

function borrarDivs() {
  var productos = document.querySelectorAll("div.ItemCardList__slot");
  productos.forEach(function (anuncio) {
    anuncio.remove();
  });
}

// Crear un observador para observar la inserción de elementos en el DOM
var observerBoton = new MutationObserver(function (mutationsList, observer) {
  for (var mutation of mutationsList) {
    if (mutation.type === "childList") {
      // Verificar si se inserta el elemento filtersBar
      if (
        mutation.addedNodes.length &&
        mutation.addedNodes[0].matches &&
        mutation.addedNodes[0].matches("div.d-flex.ng-star-inserted")
      ) {
        // Ejecutar la función para inyectar el botón
        injectButton();
        // Desconectar el observador después de ejecutar la función una vez
        observer.disconnect();
        break;
      }
    }
  }
});

// Configurar y empezar a observar cambios en el DOM
observerBoton.observe(document.body, { childList: true, subtree: true });



// Crear un observador para observar los cambios en el DOM
var observerFiltro = new MutationObserver(function (mutationsList, observer) {
  for (var mutation of mutationsList) {
    if (mutation.type === "childList") {
      // Verificar si se insertan nuevos productos
      if (mutation.addedNodes.length) {
        mutation.addedNodes.forEach(function (node) {
          if (
            node.nodeType === Node.ELEMENT_NODE &&
            node.matches &&
            node.matches("a.ItemCardList__item.ng-star-inserted")
          ) {
            // Ejecutar la función para filtrar los productos y borrar los divs
            filtrarProductos();
            borrarDivs();
          }
        });
      }
    }
  }
});

observerFiltro.observe(document.body, { childList: true, subtree: true });