Last active
October 29, 2024 15:56
:3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
await faceapi.nets.tinyFaceDetector.loadFromUri( | |
chrome.runtime.getURL("models") | |
); | |
const gigachad = new Image(); | |
gigachad.src = chrome.runtime.getURL("gigachad.png"); | |
await new Promise((resolve) => { | |
gigachad.onload = resolve; | |
}); | |
await faceapi.nets.faceLandmark68Net.loadFromUri( | |
chrome.runtime.getURL("models") | |
); | |
/** | |
* @param {HTMLImageElement} img | |
*/ | |
async function processImage(img) { | |
try { | |
if (img.width < 100 || img.height < 100) return; | |
img.setAttribute("meowning", "true"); | |
const canvas = document.createElement("canvas"); | |
canvas.width = img.width; | |
canvas.height = img.height; | |
const ctx = canvas.getContext("2d"); | |
ctx.drawImage(img, 0, 0, img.width, img.height); | |
const landmarkedDetections = await faceapi | |
.detectAllFaces(canvas, new faceapi.TinyFaceDetectorOptions()) | |
.withFaceLandmarks(); | |
for (let detection of landmarkedDetections) { | |
const { x, y, width, height } = detection.detection.box; | |
ctx.drawImage(gigachad, x, y, width, height); | |
} | |
img.src = canvas.toDataURL(); | |
} catch (error) { | |
console.error("Error processing image:", error); | |
} | |
} | |
const images = document.getElementsByTagName("img"); | |
[...images].forEach(processImage); | |
const observer = new MutationObserver((mutations) => { | |
for (let mutation of mutations) { | |
const allImages = [...mutation.addedNodes].flatMap((node) => { | |
if (node.tagName === "IMG") return [node]; | |
if (node.querySelectorAll) return [...node.querySelectorAll("img")]; | |
return []; | |
}); | |
allImages.forEach(processImage); | |
} | |
}); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 3, | |
"name": "Gigachad Face Filter", | |
"version": "1.0", | |
"description": "Applies a Gigachad filter to every face on the screen.", | |
"permissions": ["activeTab", "scripting"], | |
"host_permissions": ["<all_urls>"], | |
"content_scripts": [ | |
{ | |
"matches": ["<all_urls>"], | |
"js": ["face-api.js", "content.js"], | |
"run_at": "document_idle" | |
} | |
], | |
"web_accessible_resources": [ | |
{ | |
"resources": ["gigachad.png", "models/*", "face-api.js.map"], | |
"matches": ["<all_urls>"] | |
} | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need
face-api.js