diff --git a/README.md b/README.md index 8bb579a..e51f5a4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# katoffl +# Katoffl A browser extension that replaces 🇩🇪 with 🥔 on Twitter. diff --git a/icons/icon128.png b/icons/icon128.png new file mode 100644 index 0000000..c5a3d21 Binary files /dev/null and b/icons/icon128.png differ diff --git a/icons/icon16.png b/icons/icon16.png new file mode 100644 index 0000000..9e8c5e6 Binary files /dev/null and b/icons/icon16.png differ diff --git a/icons/icon48.png b/icons/icon48.png new file mode 100644 index 0000000..99c5e82 Binary files /dev/null and b/icons/icon48.png differ diff --git a/icons/icon96.png b/icons/icon96.png new file mode 100644 index 0000000..b1fd061 Binary files /dev/null and b/icons/icon96.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..17717f6 --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "manifest_version": 2, + "name": "Katoffl", + "description": "Replaces 🇩🇪 with 🥔 on Twitter.", + "version": "1.0", + "icons": { + "16": "icons/icon16.png", + "48": "icons/icon48.png", + "96": "icons/icon96.png", + "128": "icons/icon128.png" + }, + + "content_scripts": [ + { + "matches": ["*://*.twitter.com/*"], + "js": ["./substitute.js"], + "run_at": "document_end" + } + ] +} diff --git a/substitute.js b/substitute.js new file mode 100644 index 0000000..b01428a --- /dev/null +++ b/substitute.js @@ -0,0 +1,33 @@ +function replaceSchland (node) { + if (node.nodeName === "IMG" && node.classList.contains("Emoji")) { + if (node.src.endsWith("/1f1e9-1f1ea.png")) { + node.src = node.src.replace("/1f1e9-1f1ea.png", "/1f954.png"); + } + } else if (node.nodeName === "SPAN" && node.classList.contains("Emoji")) { + if (node.style.backgroundImage.endsWith("/1f1e9-1f1ea.png\")")) { + node.style.backgroundImage = node.style.backgroundImage.replace("/1f1e9-1f1ea.png", "/1f954.png"); + } + } else { + for (let i = 0; i < node.childNodes.length; i++) { + replaceSchland(node.childNodes[i]); + } + } +} + +replaceSchland(document.body); + +const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.addedNodes && mutation.addedNodes.length > 0) { + for (let i = 0; i < mutation.addedNodes.length; i++) { + const newNode = mutation.addedNodes[i]; + replaceSchland(newNode); + } + } + }); +}); + +observer.observe(document.body, { + childList: true, + subtree: true +});