Convert Value to Link by ID

Convert value attributes to clickable links for elements with a specific ID on https://cab.meest.cn

  1. // ==UserScript==
  2. // @name Convert Value to Link by ID
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Convert value attributes to clickable links for elements with a specific ID on https://cab.meest.cn
  6. // @author max5555
  7. // @match https://cab.meest.cn/*
  8. // @grant none
  9. // @license MIT
  10.  
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function convertValueToLink() {
  17. const elements = document.querySelectorAll('#photo-product');
  18. for (const element of elements) {
  19. const url = element.getAttribute('value');
  20. if (url && !element.nextElementSibling?.classList.contains('converted-link')) {
  21. const anchor = document.createElement('a');
  22. anchor.href = url;
  23. anchor.target = '_blank';
  24. anchor.textContent = url;
  25. anchor.classList.add('converted-link'); // To avoid adding the same link multiple times
  26. element.insertAdjacentElement('afterend', anchor);
  27. }
  28. }
  29. }
  30.  
  31. // Use a MutationObserver to detect dynamic content changes
  32. const observer = new MutationObserver(mutations => {
  33. convertValueToLink();
  34. });
  35. observer.observe(document.body, { childList: true, subtree: true });
  36.  
  37. // Convert existing elements on page load
  38. convertValueToLink();
  39. })();