>>23027390
(function() {
'use strict';
// Function to generate a simple perceptual hash of an image
function generateImageHash(imgElement, callback) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 8; // Resize to 8x8 for hashing
canvas.height = 8;
// Draw the image onto the canvas
ctx.drawImage(imgElement, 0, 0, 8, 8);
// Get pixel data
const imageData = ctx.getImageData(0, 0, 8, 8).data;
let hash = '';
// Convert to grayscale and create a hash (1 bit per pixel, 64 bits total)
for (let i = 0; i < imageData.length; i += 4) {
const grayscale = (imageData[i] * 0.3) + (imageData[i + 1] * 0.59) + (imageData[i + 2] * 0.11); // RGB to grayscale
hash += grayscale 128 ? '1' : '0'; // Compare to median (simplified)
}
callback(hash);
}
// Function to compare two hashes (Hamming distance)
function compareHashes(hash1, hash2) {
if (hash1.length !== hash2.length) return false;
let distance = 0;
for (let i = 0; i < hash1.length; i++) {
if (hash1[i] !== hash2[i]) distance++;
}
return distance < 10; // Allow some difference (tweak this threshold)
}
// Reference hash of the white cat meme (you need to precompute this)
const referenceHash = '1010101010101010…'; // Placeholder: 64-bit hash (replace with actual hash)
// Function to block posts by Mr. Pig and detect meme format
function blockMrPigAndMemes() {
const posts = document.querySelectorAll('div.post');
posts.forEach(post ={
// Check for Mr. Pig's name
const nameElement = post.querySelector('span.name');
const hasMrPig = nameElement && nameElement.textContent.trim() === 'Mr. Pig';
// Check for meme format: text patterns
const postText = post.querySelector('div.post-message');
const hasMemeText = postText && /WELL ANGRY INCH|APPARENTLY MAKE|AMERICA WINNING/i.test(postText.textContent);
// Check for meme image using hashing
const image = post.querySelector('img.post-image');
let hasMemeImage = false;
if (image) {
// Ensure the image is loaded
if (!image.complete) {
image.onload = () ={
generateImageHash(image, hash ={
hasMemeImage = compareHashes(hash, referenceHash);
if (hasMrPig || hasMemeText || hasMemeImage) {
post.style.display = 'none';
console.log('Blocked a post by Mr. Pig, matching meme text, or matching meme image');
}
});
};
} else {
generateImageHash(image, hash ={
hasMemeImage = compareHashes(hash, referenceHash);
if (hasMrPig || hasMemeText || hasMemeImage) {
post.style.display = 'none';
console.log('Blocked a post by Mr. Pig, matching meme text, or matching meme image');
}
});
}
} else {
// If no image, apply text-based and name-based blocking
if (hasMrPig || hasMemeText) {
post.style.display = 'none';
console.log('Blocked a post by Mr. Pig or matching meme text');
}
}
});
}
// Run the function on page load
blockMrPigAndMemes();
// Observe for dynamically loaded posts
const observer = new MutationObserver((mutations) ={
mutations.forEach(() ={
blockMrPigAndMemes();
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();