Advertisement
Guest User

Untitled

a guest
Oct 30th, 2024
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | Software | 0 0
  1. // ==UserScript==
  2. // @name Twitter to XCancel Redirect
  3. // @description Redirects X/Twitter links to XCancel.
  4. // @version 0.99
  5. // @author AUGUSTUS
  6. // @grant none
  7. // @icon https://miro.medium.com/v2/resize:fit:737/1*8mpu6OwgGu_-NMNo-q5oFw.jpeg (embed)
  8. // ==/UserScript==
  9.  
  10.  
  11. const XCANCEL_URL = 'xcancel.com'
  12. const TWITTER_URL = 'x.com'
  13.  
  14. function redirectToXCancel () {
  15. document.querySelectorAll('a[href*="'+ TWITTER_URL +'"]').forEach((element) => {
  16. element.href = element.href.replace(TWITTER_URL, XCANCEL_URL)
  17. element.textContent = element.textContent.replace(TWITTER_URL, XCANCEL_URL)
  18. })
  19. }
  20.  
  21. (new MutationObserver((mutations) => {
  22. let runCheck = false
  23. for (let mutation of mutations) {
  24. if (mutation.addedNodes.length || mutation.attributeName === 'href') {
  25. runCheck = true
  26. break
  27. }
  28. }
  29. if (runCheck) {
  30. redirectToXCancel()
  31. }
  32. })).observe(document.querySelector('body'), {attributeFilter: ['href'], childList: true, subtree: true})
  33.  
  34. redirectToXCancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement