(() => {
    const noDecoratePathnames = ["/kindle-dbs/manga-store/webcomic/"];
    if (noDecoratePathnames.includes(window.location.pathname)) {
        return;
    }
    const hrefMatcher = new RegExp(`^${window.location.origin}/(gp/aw/d/|([^/]+/)?dp/|gp/product/)(?<asin>[A-Z0-9]{10})\\W`);
    const decorate = (parentSelector, itemSelector) => {
        const clickHandler = (event) => { window.BrowserHost?.triggerQvWeblab(); };
        document.querySelectorAll(`${parentSelector} > ${itemSelector} a.a-link-normal`)
            .forEach(link => { if (link.href.match(hrefMatcher)?.groups['asin']) { link.addEventListener('click', clickHandler); } });
    };
    //decorate('ol.a-carousel', 'li.a-carousel-card'); // AUI carousels
    decorate('ol.a-carousel', 'li.a-carousel-card:not([class*="manga-store"])'); // AUI carousels, except the manga store ones
    decorate('ol.a-carousel', 'li.a-carousel-card > div[class*="manga-store"]'); // AUI carousels with manga store special sauce
    decorate('div[class*="grid-container"]', 'div[class*="grid"] div[class*="grid-item"]'); // Manga store ranked grids
    decorate('#browse-list-view', '.browse-clickable-item'); // Search
    decorate('#browse-grid-view', '.browse-clickable-item'); // Search on wide screens
    decorate('#series-childAsin-list', '.series-childAsin-batch > .series-childAsin-item'); // Series
    decorate('.a-section :not(.aos-single-asin-section)', '.aos-single-asin-section'); // Fancy series
})()
