Created
March 30, 2023 22:02
-
-
Save james4388/0a327abcb42471371a024d219c83969f to your computer and use it in GitHub Desktop.
Pick all brick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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