X.com to XCancel.com Redirector

Replaces xcancel.com links with xcancel.com

  1. // ==UserScript==
  2. // @name X.com to XCancel.com Redirector
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Replaces xcancel.com links with xcancel.com
  6. // @author Cucco
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to replace all xcancel.com links in DOM elements
  17. function replaceXLinks() {
  18. // Replace href attributes in anchor tags
  19. const links = document.querySelectorAll('a[href*="xcancel.com"]');
  20. links.forEach(link => {
  21. link.href = link.href.replace(/x\.com/g, 'xcancel.com');
  22. });
  23.  
  24. // Replace xcancel.com in text content (optional)
  25. const textNodes = [];
  26. const walker = document.createTreeWalker(
  27. document.body,
  28. NodeFilter.SHOW_TEXT,
  29. null,
  30. false
  31. );
  32.  
  33. let node;
  34. while (node = walker.nextNode()) {
  35. if (node.nodeValue.includes('xcancel.com')) {
  36. textNodes.push(node);
  37. }
  38. }
  39.  
  40. textNodes.forEach(node => {
  41. node.nodeValue = node.nodeValue.replace(/x\.com/g, 'xcancel.com');
  42. });
  43. }
  44.  
  45. // Run when DOM is loaded
  46. document.addEventListener('DOMContentLoaded', replaceXLinks);
  47.  
  48. // Also run periodically to catch dynamically added content
  49. setInterval(replaceXLinks, 2000);
  50.  
  51. // Intercept and modify URL before navigation
  52. const originalOpen = XMLHttpRequest.prototype.open;
  53. XMLHttpRequest.prototype.open = function() {
  54. if (arguments[1] && typeof arguments[1] === 'string') {
  55. arguments[1] = arguments[1].replace(/x\.com/g, 'xcancel.com');
  56. }
  57. return originalOpen.apply(this, arguments);
  58. };
  59.  
  60. // Intercept fetch requests
  61. const originalFetch = window.fetch;
  62. window.fetch = function() {
  63. if (arguments[0] && typeof arguments[0] === 'string') {
  64. arguments[0] = arguments[0].replace(/x\.com/g, 'xcancel.com');
  65. } else if (arguments[0] && arguments[0] instanceof Request) {
  66. arguments[0] = new Request(
  67. arguments[0].url.replace(/x\.com/g, 'xcancel.com'),
  68. arguments[0]
  69. );
  70. }
  71. return originalFetch.apply(this, arguments);
  72. };
  73. })();