Autotrader UK - remove ads from search results

Removes all "Ad" and "You may also like" items from autotrader.co.uk search results

目前为 2024-12-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Autotrader UK - remove ads from search results
  3. // @namespace https://autotrader.co.uk
  4. // @version 0.1
  5. // @description Removes all "Ad" and "You may also like" items from autotrader.co.uk search results
  6. // @author Steve Chambers
  7. // @license MIT
  8. // @match https://www.autotrader.co.uk/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=autotrader.co.uk
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to remove the targeted <li> elements
  16. function removeTargetedListItems() {
  17. document.querySelectorAll('li').forEach(li => {
  18. if (li.querySelector('span')?.textContent.trim() === 'Ad' ||
  19. li.querySelector('span')?.textContent.trim() === 'You may also like') {
  20. li.remove();
  21. }
  22. });
  23. }
  24.  
  25. // Run the function on page load
  26. removeTargetedListItems();
  27.  
  28. // Observe the DOM for dynamically loaded content
  29. const observer = new MutationObserver(() => {
  30. removeTargetedListItems();
  31. });
  32.  
  33. observer.observe(document.body, {
  34. childList: true,
  35. subtree: true
  36. });
  37. })();