Skip to content

Instantly share code, notes, and snippets.

@s-shin
Last active November 28, 2017 14:02
Show Gist options
  • Save s-shin/1b647708b058316977a76b0a372d58ba to your computer and use it in GitHub Desktop.
Save s-shin/1b647708b058316977a76b0a372d58ba to your computer and use it in GitHub Desktop.
Copy, paste and run in dev console.
(function() {
const THRESHOLD = 400;
function isEndOfList() {
return document.querySelector("#endOfListMarker") !== null;
}
function scroll(top) {
document.scrollingElement.scrollTop = top;
}
function scrollToLastItem() {
const top = document.querySelector("#g-items").getBoundingClientRect().bottom
+ document.scrollingElement.scrollTop;
scroll(top);
}
function isWishListPage() {
return document.querySelector("#wl-item-view") !== null;
// or we can also check the URL.
}
function loadAll(cb) {
if (!isEndOfList()) {
scrollToLastItem();
setTimeout(() => loadAll(cb), 1000);
return;
}
cb();
}
function getItems() {
const elItems = document.querySelectorAll("#g-items [id^=item_]");
return Array.from(elItems).map(el => {
const elName = el.querySelector("[id^=itemName_]");
const elByline = el.querySelector("[id^=item-byline-]");
const elPrice = el.querySelector("[id^=itemPrice_] .a-price-whole");
return {
name: elName.textContent,
byline: elByline.textContent,
price: elPrice.textContent,
}
});
}
function main() {
if (!isWishListPage()) {
console.error("This page does not contain the wish list.");
}
loadAll(() => {
getItems().forEach(item => {
if (item.price < THRESHOLD) {
console.log(item);
}
})
});
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment