Skip to content

Instantly share code, notes, and snippets.

@orbitrod
Last active May 22, 2023 17:27
Show Gist options
  • Save orbitrod/bacc256dac280e79f80a29b6baef069e to your computer and use it in GitHub Desktop.
Save orbitrod/bacc256dac280e79f80a29b6baef069e to your computer and use it in GitHub Desktop.
Tampermonkey Userscript - eBay Hide Zero Quantity Items
// ==UserScript==
// @name eBay Hide Zero Quantity Items
// @namespace https://www.ebay.com
// @version 1.0
// @description Hide rows of items with zero quantity on eBay active listings page and add a button to show them.
// @author Forzza Services
// @match https://www.ebay.com/sh/lst/active
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Add show/hide zero quantity items button
function addShowZeroQuantityButton() {
const buttonContainer = document.querySelector('.bulk-actions-wrapper .action-group');
const showButton = document.createElement('button');
showButton.innerHTML = 'Hide Zero Quantity Items';
showButton.className = 'btn btn--small btn--secondary';
showButton.style.backgroundColor = '#fff3cd';
showButton.style.color = '#000000';
showButton.style.border = '1px solid #ffc107';
let showZeroQuantity = false;
function toggleShowZeroQuantity() {
const rows = document.querySelectorAll('.grid-row');
if (showZeroQuantity) {
rows.forEach((row) => {
row.style.display = '';
});
showButton.innerHTML = 'Hide Zero Quantity Items';
} else {
rows.forEach((row) => {
const quantity = row.querySelector('.shui-dt-column__availableQuantity span');
if (quantity && parseInt(quantity.innerText) === 0) {
row.style.display = 'none';
}
});
showButton.innerHTML = 'Show Zero Quantity Items';
}
showZeroQuantity = !showZeroQuantity;
// Count the number of visible items
const visibleItems = Array.from(rows).filter((row) => row.style.display !== 'none');
countLabel.innerHTML = `Items shown: ${visibleItems.length}`;
}
showButton.addEventListener('click', toggleShowZeroQuantity);
const countLabel = document.createElement('span');
countLabel.id = 'show-zero-quantity-count';
countLabel.style.marginLeft = '5px';
countLabel.style.fontSize = '12px';
countLabel.style.color = '#000000';
// Create a container for the button and count label
const container = document.createElement('div');
container.style.display = 'flex';
container.style.alignItems = 'center';
// Append the elements to the container
container.appendChild(showButton);
container.appendChild(countLabel);
// Append the container to the button container
buttonContainer.appendChild(container);
}
// Execute when the page is fully loaded
window.addEventListener('load', () => {
addShowZeroQuantityButton();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment