Skip to content

Instantly share code, notes, and snippets.

@apricot13
Last active January 4, 2022 15:11
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 apricot13/d8c2f74b1175d63a84cbbc957d33a7bf to your computer and use it in GitHub Desktop.
Save apricot13/d8c2f74b1175d63a84cbbc957d33a7bf to your computer and use it in GitHub Desktop.
Amazon wishlist Sort by Price Dropped By Bookmark (copy paste this entire thing into the URL part of a bookmark in chrome)
javascript:const allItems=document.getElementById("g-items");allItems.style.display="flex",allItems.style.flexDirection="column",allItems.style.flexFlow="column-reverse";const items=allItems.querySelectorAll("li"),prices=[];[...items].forEach(e=>{let t=e.getAttribute("data-price");e=e.getAttribute("data-itemid");t=isFinite(t)&&!isNaN(t)?t:0,prices.push([e,t])}),prices.sort((e,t)=>t[1]-e[1]),prices.forEach((e,t)=>{if(""!==e[0]){e='[data-itemid="'+e[0]+'"]';console.log(e);const l=document.querySelector(e);console.log(e,l),l&&(l.style.order=t)}});
const allItems = document.getElementById("g-items");
allItems.style.display = "flex";
allItems.style.flexDirection = "column";
allItems.style.flexFlow = "column-reverse";
const items = allItems.querySelectorAll("li");
const prices = [];
[...items].forEach((item) => {
let price = item.getAttribute('data-price');
let dataItemId = item.getAttribute('data-itemid');
price = (isFinite(price) && !isNaN(price)) ? price : 0.0;
prices.push([dataItemId, price])
});
// badly sorting the arrays and applying order
prices.sort((a, b) => b[1] - a[1])
prices.forEach((data, i) => {
if(data[0] !== '') {
const searchQuery = '[data-itemid="'+data[0]+'"]';
console.log(searchQuery)
const itemWithItemId = document.querySelector(searchQuery);
console.log(searchQuery, itemWithItemId)
if(itemWithItemId) {
itemWithItemId.style.order = i
}
}
})
javascript:const allItems = document.getElementById('g-items');allItems.style.display = 'flex';allItems.style.flexDirection = 'column';allItems.style.flexFlow = 'column-reverse';const items = allItems.querySelectorAll('li');[...items].forEach((item) => { const $priceDrop = item.querySelector('span[id^="itemPriceDrop_"]'); /* Price dropped 27% */ const priceDropText = ($priceDrop) ? $priceDrop.innerHTML.trim() : %27%27; const r = /\d+/; const priceDroppedPercentage = (r.exec(priceDropText)) ? r.exec(priceDropText)[0] : 0; item.style.order = priceDroppedPercentage;})
const allItems = document.getElementById("g-items");
allItems.style.display = "flex";
allItems.style.flexDirection = "column";
allItems.style.flexFlow = "column-reverse";
const items = allItems.querySelectorAll("li");
[...items].forEach((item) => {
const $priceDrop = item.querySelector('span[id^="itemPriceDrop_"]');
/* Price dropped 27% */ const priceDropText = $priceDrop ? $priceDrop.innerHTML.trim() : "";
const r = /\d+/;
const priceDroppedPercentage = r.exec(priceDropText) ? r.exec(priceDropText)[0] : 0;
item.style.order = priceDroppedPercentage;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment