Last active
January 4, 2022 15:11
-
-
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)
This file contains 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
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)}}); |
This file contains 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 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 | |
} | |
} | |
}) |
This file contains 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
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;}) |
This file contains 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 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