Files
background.js
content.js
manifest.json
popup.css
popup.html
popup.js
Code
6 749
content.js
// Tracking distorted elements to avoid double-processing
const DISTORTED_ATTR = 'data-slightly-wrong';
let settings = null;
let isProcessing = false;
// Initialize
init();
async function init() {
settings = await chrome.storage.local.get({
enabled: false,
intensity: 30,
editPrices: true,
editHeadlines: true,
editNumbers: true,
editLayout: false,
editTimestamps: false,
editMeta: false
});
if (!settings.enabled) return;
// Process existing content
processPage();
// Watch for dynamic content
const observer = new MutationObserver((mutations) => {
if (!isProcessing) {
isProcessing = true;
setTimeout(() => {
processPage();
isProcessing = false;
}, 500);
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
function processPage() {
if (!settings.enabled) return;
const elements = document.querySelectorAll('body *:not(script):not(style):not([' + DISTORTED_ATTR + '])');
elements.forEach(element => {
// Skip if already processed
if (element.hasAttribute(DISTORTED_ATTR)) return;
// Skip input fields and critical UI
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA' || element.tagName === 'SELECT') return;
// Probability check based on intensity
const roll = Math.random() * 100;
if (roll > settings.intensity) return;
// Try different distortions
if (settings.editPrices && tryDistortPrice(element)) return;
if (settings.editNumbers && tryDistortNumber(element)) return;
if (settings.editHeadlines && tryDistortHeadline(element)) return;
if (settings.editTimestamps && tryDistortTimestamp(element)) return;
if (settings.editLayout && tryDistortLayout(element)) return;
if (settings.editMeta && tryInsertMeta(element)) return;
});
}
function tryDistortPrice(element) {
if (!element.textContent) return false;
const text = element.textContent.trim();
// Match currency patterns: $19.99, €24.50, £12.00, 29,99€
const priceRegex = /^[\$€£¥]?\s*[\d,]+\.?\d{0,2}\s*[\$€£¥]?$/;
if (!priceRegex.test(text)) return false;
if (text.length > 20) return false; // Avoid long strings
// Extract number
const numMatch = text.match(/[\d,]+\.?\d{0,2}/);
if (!numMatch) return false;
const numStr = numMatch[0].replace(/,/g, '');
const num = parseFloat(numStr);
if (isNaN(num) || num === 0) return false;
// Adjust by ±3% to ±15%
const change = (Math.random() * 0.12 + 0.03) * (Math.random() > 0.5 ? 1 : -1);
const newNum = num * (1 + change);
// Format with 2 decimals
const newNumStr = newNum.toFixed(2);
const newText = text.replace(/[\d,]+\.?\d{0,2}/, newNumStr);
element.textContent = newText;
element.setAttribute(DISTORTED_ATTR, 'price');
return true;
}
function tryDistortNumber(element) {
if (!element.textContent) return false;
const text = element.textContent.trim();
// Match standalone numbers with optional suffixes: 1.2K, 45M, 234,567
const numberRegex = /^\d{1,3}(,?\d{3})*(\.\d+)?[KMB]?\s*(views?|likes?|subscribers?|followers?|comments?)?$/i;
if (!numberRegex.test(text)) return false;
if (text.length > 25) return false;
// Extract the number
const numMatch = text.match(/^[\d,\.]+[KMB]?/i);
if (!numMatch) return false;
const numStr = numMatch[0];
let num = parseFloat(numStr.replace(/,/g, ''));
let suffix = '';
// Handle K/M/B suffixes
if (numStr.includes('K')) {
num *= 1000;
suffix = 'K';
} else if (numStr.includes('M')) {
num *= 1000000;
suffix = 'M';
} else if (numStr.includes('B')) {
num *= 1000000000;
suffix = 'B';
}
if (isNaN(num) || num === 0) return false;
// Adjust by ±5% to ±20%
const change = (Math.random() * 0.15 + 0.05) * (Math.random() > 0.5 ? 1 : -1);
let newNum = Math.round(num * (1 + change));
// Format with suffix
let formattedNum;
if (suffix === 'K') {
formattedNum = (newNum / 1000).toFixed(1) + 'K';
} else if (suffix === 'M') {
formattedNum = (newNum / 1000000).toFixed(1) + 'M';
} else if (suffix === 'B') {
formattedNum = (newNum / 1000000000).toFixed(1) + 'B';
} else if (newNum >= 1000) {
formattedNum = newNum.toLocaleString();
} else {
formattedNum = newNum.toString();
}
const newText = text.replace(/^[\d,\.]+[KMB]?/i, formattedNum);
element.textContent = newText;
element.setAttribute(DISTORTED_ATTR, 'number');
return true;
}
function tryDistortHeadline(element) {
// Only target headline tags and article titles
if (!['H1', 'H2', 'H3'].includes(element.tagName)) return false;
if (!element.textContent) return false;
const text = element.textContent.trim();
// Skip if too short or too long
if (text.length < 15 || text.length > 150) return false;
// Skip if contains only uppercase (likely a logo)
if (text === text.toUpperCase()) return false;
// Apply random distortion
const distortions = [
() => distortWithQualifier(text),
() => distortWithNumber(text),
() => distortWithSubstitution(text)
];
const distortion = distortions[Math.floor(Math.random() * distortions.length)];
const newText = distortion();
if (newText && newText !== text) {
element.textContent = newText;
element.setAttribute(DISTORTED_ATTR, 'headline');
return true;
}
return false;
}
function distortWithQualifier(text) {
const qualifiers = ['Almost', 'Nearly', 'About', 'Roughly', 'Approximately', 'Sort of'];
const removalWords = ['Top', 'Best', 'Amazing', 'Incredible', 'Ultimate'];
// 50% chance to add qualifier, 50% to remove word
if (Math.random() > 0.5) {
// Add qualifier at the start
const qualifier = qualifiers[Math.floor(Math.random() * qualifiers.length)];
return qualifier + ' ' + text;