Skip to content

Instantly share code, notes, and snippets.

@james4388
Created March 30, 2023 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james4388/0a327abcb42471371a024d219c83969f to your computer and use it in GitHub Desktop.
Save james4388/0a327abcb42471371a024d219c83969f to your computer and use it in GitHub Desktop.
Pick all brick
const wait = async (time) => new Promise((resolve) => setTimeout(resolve, time));
const pickAll = async () => {
const btns = document.querySelectorAll('button[data-test="pab-item-btn-pick"]');
for (const btn of btns) {
btn.click();
await wait(100);
}
}
const getSetQuantity = (itemEl) => {
const quantityEl = itemEl.querySelector('span[data-test="pab-quantity-in-set"]');
if (quantityEl) {
const text = quantityEl.textContent;
return text.split(' ').pop();
}
}
const updateQuantity = (itemEl) => {
const quantity = getSetQuantity(itemEl);
if (quantity) {
const inputEl = itemEl.querySelector('input[data-test="pab-item-quantity"]');
if (inputEl.value !== quantity) {
const setValue = Object.getOwnPropertyDescriptor(inputEl.__proto__, 'value').set;
const event = new Event('input', { bubbles: true });
setValue.call(inputEl, quantity);
inputEl.dispatchEvent(event);
}
}
}
const updateQuantityAll = async () => {
const items = document.querySelectorAll('li[class^="ElementsList_leaf"]');
for (const item of items) {
updateQuantity(item);
await wait(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment