More JS tweaks

restock-visualselector-refactor
dgtlmoon 11 months ago
parent 62b55df7e5
commit b045a72460

@ -126,10 +126,7 @@ function isItemInStock() {
}
}
// Create an array to hold the visible elements
const elementsToScan = [];
// Call collectVisibleElements with the starting parent element
collectVisibleElements(document.body, elementsToScan);
var elementText = "";
@ -143,7 +140,6 @@ function isItemInStock() {
continue
}
elementText = "";
if (element.tagName.toLowerCase() === "input") {
elementText = element.value.toLowerCase();
@ -154,6 +150,7 @@ function isItemInStock() {
if (elementText.length) {
// try which ones could mean its in stock
if (negateOutOfStockRegex.test(elementText)) {
console.log(`Negating/overriding 'Out of Stock' back to "Possibly in stock" found "${elementText}"`)
return 'Possibly in stock';
}
}
@ -167,7 +164,6 @@ function isItemInStock() {
if (element.getBoundingClientRect().top + window.scrollY >= vh || element.getBoundingClientRect().top + window.scrollY <= 100) {
continue
}
if (element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0) {
elementText = "";
if (element.tagName.toLowerCase() === "input") {
elementText = element.value.toLowerCase();
@ -179,13 +175,14 @@ function isItemInStock() {
// and these mean its out of stock
for (const outOfStockText of outOfStockTexts) {
if (elementText.includes(outOfStockText)) {
console.log(`Selected 'Out of Stock' - found text "${outOfStockText}"`)
return outOfStockText; // item is out of stock
}
}
}
}
}
console.log(`Returning 'Possibly in stock' - cant' find any useful matching text`)
return 'Possibly in stock'; // possibly in stock, cant decide otherwise.
}

@ -139,7 +139,7 @@ visibleElementsArray.forEach(function (element) {
bbox = element.getBoundingClientRect();
// Skip really small ones, and where width or height ==0
if (bbox['width'] * bbox['height'] < 100) {
if (bbox['width'] * bbox['height'] < 10) {
return
}

Loading…
Cancel
Save