Skip to content

Instantly share code, notes, and snippets.

@tals
Created February 23, 2025 22:26
Show Gist options
  • Save tals/2ac1f7a4965acc03519966318dc3acb8 to your computer and use it in GitHub Desktop.
Save tals/2ac1f7a4965acc03519966318dc3acb8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Streeteasy "Luxury" to Poop Emoji (Stable)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Replaces superlative words with a stable, hashed poop-related emoji on streeteasy pages.
// @match *://streeteasy.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// Hide the page until modifications are complete.
document.documentElement.style.display = 'none';
// List of poop emojis and superlative words.
const emojis = ["💩", "🤮", "🚽", "🧻"];
const words = [
"luxury", "ultimate", "premium", "exclusive","high-end", "exceptional", "sophisticated", "serene", "stunning", "boutique"
];
const regex = new RegExp(`\\b(?:${words.join('|')})\\b`, 'gi');
// A simple hash function.
const simpleHash = s => {
let hash = 0;
for (let i = 0; i < s.length; i++) {
hash = ((hash << 5) - hash) + s.charCodeAt(i);
hash |= 0;
}
return hash;
};
// Recursively process text nodes.
const processNode = node => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(regex, (match, offset, str) => {
const context = str.substring(Math.max(0, offset - 10), offset + match.length + 10);
const idx = Math.abs(simpleHash(context) + offset) % emojis.length;
return emojis[idx];
});
} else {
node.childNodes.forEach(processNode);
}
};
// Process the document and set up a MutationObserver for dynamic changes.
const processDocument = () => {
processNode(document.body);
new MutationObserver(mutations =>
mutations.forEach(m => m.addedNodes.forEach(processNode))
).observe(document.body, { childList: true, subtree: true });
};
document.addEventListener('DOMContentLoaded', () => {
processDocument();
document.documentElement.style.display = '';
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment