Amazon ShoptheLook Enhancer

Enhances the Amazon ShoptheLook page by adding product titles to each item.

  1. // ==UserScript==
  2. // @name Amazon ShoptheLook Enhancer
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.amazon.com/shopthelook?q=*
  5. // @grant GM_xmlhttpRequest
  6. // @version 1.1
  7. // @license MIT
  8. // @description Enhances the Amazon ShoptheLook page by adding product titles to each item.
  9. // ==/UserScript==
  10.  
  11. function enhanceShoptheLook() {
  12. const sectionElement = document.querySelector('#product_grid_container > div > section');
  13. if (!sectionElement) return;
  14.  
  15. const articleElements = sectionElement.querySelectorAll('article');
  16. let newHtml = '';
  17. articleElements.forEach(article => {
  18. const imageContainerLink = article.querySelector('section.item-image-container > div > div > a');
  19. if (!imageContainerLink) return;
  20.  
  21. const href = imageContainerLink.getAttribute('href');
  22. if (!href) return;
  23.  
  24. GM_xmlhttpRequest({
  25. method: 'GET',
  26. url: href,
  27. onload: function(response) {
  28. const parser = new DOMParser();
  29. const doc = parser.parseFromString(response.responseText, 'text/html');
  30. const productTitleElement = doc.querySelector('#productTitle');
  31. if (productTitleElement) {
  32. const originalArticleHtml = article.outerHTML;
  33. const titleHtml = productTitleElement.outerHTML;
  34. newHtml += originalArticleHtml.replace('</article>', titleHtml + '</article>');
  35. } else {
  36. newHtml += article.outerHTML;
  37. }
  38. }
  39. });
  40. });
  41.  
  42. const originalSection = document.querySelector('#product_grid_container > div > section');
  43. originalSection.innerHTML = newHtml;
  44. }
  45.  
  46. enhanceShoptheLook();
  47. window.addEventListener('load', enhanceShoptheLook);
  48. window.addEventListener('hashchange', enhanceShoptheLook);