Skip to content

Instantly share code, notes, and snippets.

@webprogramozo
Last active September 25, 2022 11:52
Show Gist options
  • Save webprogramozo/c0cfe693d9ce10528386e49df43ca06b to your computer and use it in GitHub Desktop.
Save webprogramozo/c0cfe693d9ce10528386e49df43ca06b to your computer and use it in GitHub Desktop.
Auto-highlight the current main- and subcategory on Tesco Online website's main menu
const $fe = function(selector, callable){[].forEach.call(document.querySelectorAll(selector),callable);};
const $fei = function(selector, callable, interval){setInterval(function(){$fe(selector, callable);}, interval);};
const breadcumbSelector = '.beans-breadcrumb__list-item a[href] span.beans-link__text';
$fei(
breadcumbSelector, function(spanLinkItem){
const parentHref = spanLinkItem.parentElement.getAttribute('href');
const finalHref = parentHref.slice(0,-4) + "?include-children=true";
const finalSelector = `li.menu__item a[href='${finalHref}']`;
const formatClass = 'bandi-highlight';
const item = document.querySelector(finalSelector);
if(item){item.parentElement.classList.add(formatClass);}
},
50
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment