Comic Curseifier

Replaces random words on webpages with comic-style curses like @#$%!&*

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

// ==UserScript==
// @name         Comic Curseifier
// @namespace    http://kapow.bam/
// @version      1.0
// @description  Replaces random words on webpages with comic-style curses like @#$%!&*
// @match        *://*/*
// @run-at       document-idle
// @grant        none
// @license MIT 
// ==/UserScript==

(function () {
  'use strict';

  const CHANCE = 0.03; // 8% of words replaced
  const SYMBOLS = ['@', '#', '$', '%', '&', '*', '!', '?'];

  function generateComicCensor(length = 4) {
    let out = '';
    for (let i = 0; i < length; i++) {
      out += SYMBOLS[Math.floor(Math.random() * SYMBOLS.length)];
    }
    return out;
  }

  const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, {
    acceptNode: (node) => {
      const tag = node.parentNode?.tagName;
      return node.nodeValue.trim() &&
        tag &&
        !['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT'].includes(tag.toUpperCase())
        ? NodeFilter.FILTER_ACCEPT
        : NodeFilter.FILTER_REJECT;
    }
  });

  let node;
  while ((node = walker.nextNode())) {
    const original = node.nodeValue;
    const words = original.split(/(\s+)/); // preserve spaces
    let changed = false;

    for (let i = 0; i < words.length; i++) {
      if (/\w{3,}/.test(words[i]) && Math.random() < CHANCE) {
        words[i] = generateComicCensor(Math.min(words[i].length, 6));
        changed = true;
      }
    }

    if (changed) {
      node.nodeValue = words.join('');
    }
  }

  console.log('🤬 Comic Curseifier activated.');
})();