Make ppv.land/ft Chat Links Clickable

Turns URLs in chat messages into clickable links without affecting usernames or badges

  1. // ==UserScript==
  2. // @name Make ppv.land/ft Chat Links Clickable
  3. // @namespace https://ppv.land/ft
  4. // @version 1.2.1
  5. // @description Turns URLs in chat messages into clickable links without affecting usernames or badges
  6. // @match https://ppv.land/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to make URLs clickable while preserving styles and usernames
  15. function makeLinksClickable() {
  16. const messages = document.querySelectorAll('.message-text');
  17.  
  18. messages.forEach(message => {
  19. // Skip if links already processed
  20. if (message.dataset.linksProcessed) return;
  21.  
  22. // Separate the username part from the message text
  23. const usernameEnd = message.innerHTML.indexOf(':') + 1;
  24. const usernamePart = message.innerHTML.slice(0, usernameEnd);
  25. const textPart = message.innerHTML.slice(usernameEnd);
  26.  
  27. // Only modify URLs in the text part, preserving any special username styling
  28. const urlRegex = /(https?:\/\/[^\s]+)/g;
  29. const updatedTextPart = textPart.replace(urlRegex, (url) => `<a href="${url}" target="_blank" style="color: inherit;">${url}</a>`);
  30.  
  31. // Combine the username part and the updated text part
  32. message.innerHTML = usernamePart + updatedTextPart;
  33. message.dataset.linksProcessed = 'true';
  34. });
  35. }
  36.  
  37. // Run the function initially and whenever new messages are added
  38. makeLinksClickable();
  39. const observer = new MutationObserver(makeLinksClickable);
  40. observer.observe(document.getElementById('message-list'), { childList: true });
  41. })();