Skip to content

Instantly share code, notes, and snippets.

@raphaelrk
Last active September 12, 2023 16:28
Show Gist options
  • Save raphaelrk/da99f0f06110374e36361e3c42e7e0f2 to your computer and use it in GitHub Desktop.
Save raphaelrk/da99f0f06110374e36361e3c42e7e0f2 to your computer and use it in GitHub Desktop.
/// InstacartSponsoredItemsBlocker.js
console.log("InstacartSponsoredItemsBlocker started");
document.addEventListener('DOMContentLoaded', (event) => {
// remove sponsored items
// setInterval(() => [...document.querySelectorAll('li')].map(elt => elt.innerText.includes('Sponsored') ? elt.style.display = 'none' : null), 500);
// make sponsored items have low opacity
setInterval(() => [...document.querySelectorAll('li')].map(elt => elt.innerText.includes('Sponsored') ? elt.style.opacity = '0.15' : null), 500);
// give "likely out of stock" items a pink background
setInterval(() =>
[...document.querySelectorAll('li')].filter(elt => elt.innerText.includes('Request')).map(elt => {
elt.style.padding = '8px'
elt.style.backgroundColor = '#ff9999'
}),
500
);
// sort by lowest price
const sortByLowestPrice = () => {
let lowestPriceInterval;
lowestPriceInterval = setInterval(() => {
let seeLowestFirst = document.querySelector(`li[id*='priceAsc']`);
if (seeLowestFirst) {
console.log("sorting by lowest price!");
clearInterval(lowestPriceInterval);
seeLowestFirst.click();
seeLowestFirst.click(); // click again to remove dropdown
} else {
// console.log("not yet sorting by lowest price");
}
}, 500);
};
sortByLowestPrice();
// sort by lowest price any time url changes
let pathname = { current: window.location.pathname };
setInterval(() => {
if (window.location.pathname !== pathname.current) {
pathname.current = window.location.pathname;
sortByLowestPrice();
}
}, 500);
});
@raphaelrk
Copy link
Author

uBlock Origin instructions:

1. Add to filters

  • Go to uBlock Origin settings > My filters
  • for me this is at chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/dashboard.html#1p-filters.html
  • Add instacart.com##+js(InstacartSponsoredItemsBlocker.js)
  • (The first line of this gist is /// InstacartSponsoredItemsBlocker.js which is where uBlock gets the filename from, with the file being the block of content below it, and I believe a blank line is considered to signal the end of the file which is why there are no blank lines)

2. Add to userResourcesLocation

For more information see Scriptlet injection. There's also a uBlock subreddit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment