Only Illegal Aliens

Replaces leftist terminology with "illegal alien" on all websites

  1. // ==UserScript==
  2. // @name Only Illegal Aliens
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.1
  5. // @description Replaces leftist terminology with "illegal alien" on all websites
  6. // @author adamlproductions
  7. // @match *://*
  8. // @match *://*/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const phrases = [
  17. 'illegal migrant',
  18. 'undocumented immigrant',
  19. 'illegal immigrant',
  20. 'undocumented person',
  21. 'unauthorized migrant',
  22. 'non-citizen',
  23. 'noncitizen',
  24. 'unauthorized immigrant',
  25. 'migrant',
  26. 'undocumented'
  27. ];
  28.  
  29. function escapeRegex(string) {
  30. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  31. }
  32.  
  33. const regex = new RegExp(
  34. phrases.map(phrase => `\\b${escapeRegex(phrase)}(s?)\\b`).join('|'),
  35. 'gi'
  36. );
  37.  
  38. function isEditableElement(node) {
  39. while (node) {
  40. if (node.nodeType === Node.ELEMENT_NODE) {
  41. const tagName = node.tagName.toLowerCase();
  42. if (tagName === 'input' || tagName === 'textarea') {
  43. return true;
  44. }
  45. if (node.hasAttribute('contenteditable') && node.getAttribute('contenteditable') !== 'false') {
  46. return true;
  47. }
  48. }
  49. node = node.parentNode;
  50. }
  51. return false;
  52. }
  53.  
  54. function replaceText(node) {
  55. if (node.nodeType === Node.TEXT_NODE) {
  56. if (!isEditableElement(node)) {
  57. let text = node.textContent;
  58. text = text.replace(regex, (match, ...groups) => {
  59. const pluralIndicator = match[match.length - 1];
  60. console.log("pluralIndicator:", pluralIndicator);
  61. return pluralIndicator === 's' ? 'illegal aliens' : 'illegal alien';
  62. });
  63. node.textContent = text;
  64. }
  65. } else if (node.nodeType === Node.ELEMENT_NODE) {
  66. const tagName = node.tagName.toLowerCase();
  67. if (tagName !== 'script' && tagName !== 'style' && tagName !== 'input' && tagName !== 'textarea' && !node.hasAttribute('contenteditable')) {
  68. for (let child of node.childNodes) {
  69. replaceText(child);
  70. }
  71. }
  72. }
  73. }
  74.  
  75. const observer = new MutationObserver((mutations) => {
  76. mutations.forEach((mutation) => {
  77. mutation.addedNodes.forEach((node) => {
  78. replaceText(node);
  79. });
  80. });
  81. });
  82.  
  83. observer.observe(document.body, {
  84. childList: true,
  85. subtree: true
  86. });
  87.  
  88. replaceText(document.body);
  89. })();