4345435hhhi99

h3h3 to Pedo_Troll

Sep 1st, 2025 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | Source Code | 0 0
  1. Structure:
  2. h3h3-swap/
  3. ├─ manifest.json
  4. ├─ content.js
  5.  
  6. 1. Open chrome://extensions.
  7. 2. Toggle Developer mode (top-right).
  8. 3. Click Load unpacked and select your h3h3-swap/ folder.
  9.  
  10. manifest.json
  11.  
  12. {
  13. "manifest_version": 3,
  14. "name": "H3H3 Name Swap",
  15. "description": "On r/h3h3productions, replace 'Ethan' / 'Ethan Klein' with 'Pedo_Troll'.",
  16. "version": "1.0.0",
  17. "content_scripts": [
  18. {
  19. "matches": [
  20. "https://www.reddit.com/r/h3h3productions/*",
  21. "https://old.reddit.com/r/h3h3productions/*",
  22. "https://www.reddit.com/r/H3H3Productions/*",
  23. "https://old.reddit.com/r/H3H3Productions/*"
  24. ],
  25. "js": ["content.js"],
  26. "run_at": "document_idle"
  27. }
  28. ]
  29. }
  30.  
  31.  
  32. content.js
  33.  
  34. const RE_FULL = /\bEthan Klein\b/g;
  35. const RE_FIRST = /\bEthan\b/g;
  36. const REPLACEMENT = "Pedo_Troll";
  37. const SKIP_TAGS = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "CODE", "PRE", "TEXTAREA"]);
  38. function isEditable(el) {
  39. if (!el || el === document.body) return false;
  40. if (el.nodeType !== 1) return isEditable(el.parentNode);
  41. const tag = el.tagName;
  42. if (SKIP_TAGS.has(tag)) return true;
  43. const ce = el.getAttribute("contenteditable");
  44. if (ce === "" || ce === "true") return true;
  45. if (tag === "INPUT") return true;
  46. return isEditable(el.parentNode);
  47. }
  48.  
  49. function replaceInTextNode(node) {
  50. const original = node.nodeValue;
  51. if (!original || original.indexOf("Ethan") === -1) return;
  52.  
  53. let updated = original.replace(RE_FULL, REPLACEMENT).replace(RE_FIRST, REPLACEMENT);
  54. if (updated !== original) {
  55. node.nodeValue = updated;
  56. }
  57. }
  58.  
  59. function walkAndReplace(root) {
  60. const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
  61. acceptNode(node) {
  62. if (isEditable(node.parentNode)) return NodeFilter.FILTER_REJECT;
  63. if (!node.nodeValue || !node.nodeValue.trim()) return NodeFilter.FILTER_REJECT;
  64. return NodeFilter.FILTER_ACCEPT;
  65. }
  66. });
  67. const toProcess = [];
  68. let n;
  69. while ((n = walker.nextNode())) toProcess.push(n);
  70. toProcess.forEach(replaceInTextNode);
  71. }
  72.  
  73. function init() {
  74. walkAndReplace(document.body);
  75. const mo = new MutationObserver((mutations) => {
  76. for (const m of mutations) {
  77. if (m.type === "childList") {
  78. m.addedNodes.forEach((node) => {
  79. if (node.nodeType === 1) {
  80. if (!isEditable(node)) walkAndReplace(node);
  81. } else if (node.nodeType === 3) {
  82. replaceInTextNode(node);
  83. }
  84. });
  85. } else if (m.type === "characterData" && m.target.nodeType === 3) {
  86. replaceInTextNode(m.target);
  87. }
  88. }
  89. });
  90.  
  91. mo.observe(document.body, {
  92. subtree: true,
  93. childList: true,
  94. characterData: true
  95. });
  96. }
  97.  
  98. if (document.readyState === "loading") {
  99. document.addEventListener("DOMContentLoaded", init);
  100. } else {
  101. init();
  102. }
  103.  
Tags: h3h3
Advertisement
Add Comment
Please, Sign In to add comment