Make URLS clickable in MAL aboutme

This script makes URLS clickable in any profile! (for modern about me.)

  1. // ==UserScript==
  2. // @name Make URLS clickable in MAL aboutme
  3. // @namespace http://myanimelist.net/profile/kyoyatempest
  4. // @version 1.1
  5. // @description This script makes URLS clickable in any profile! (for modern about me.)
  6. // @author kyoyacchi
  7. // @match https://myanimelist.net/profile/*
  8. // @license MIT
  9. // @icon https://myanimelist.net/favicon.ico
  10. // ==/UserScript==
  11.  
  12. const linkify = t => {
  13. const isValidHttpUrl = s => {
  14. let u
  15. try {u = new URL(s)}
  16. catch (_) {return false}
  17. return u.protocol.startsWith("http")
  18. }
  19. const m = t.match(/(?<=\s|^)[a-zA-Z0-9-:/]+\.[a-zA-Z0-9-].+?(?=[.,;:?!-]?(?:\s|$))/g)
  20. if (!m) return t
  21. const a = []
  22. m.forEach(x => {
  23. const [t1, ...t2] = t.split(x)
  24. a.push(t1)
  25. t = t2.join(x)
  26. const y = (!(x.match(/:\/\//)) ? 'https://' : '') + x
  27. if (isNaN(x) && isValidHttpUrl(y))
  28. a.push('<a href="' + y.replace("<br>","") + '" target="_blank">' + y.split('/')[2] + '</a>')
  29. else
  30. a.push(x)
  31. })
  32. a.push(t)
  33. return a.join('')
  34. }
  35. //https://stackoverflow.com/a/71734086/19276081
  36.  
  37.  
  38. let i =document.querySelector(".c-aboutme-text")
  39. if (!i) return
  40. i.innerHTML = linkify(i.innerHTML)