Skip to content

Commit

Permalink
Add extension files
Browse files Browse the repository at this point in the history
  • Loading branch information
1maetsch committed Jun 30, 2018
1 parent bedf697 commit 691960d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# katoffl
# Katoffl
A browser extension that replaces 🇩🇪 with 🥔 on Twitter.
Binary file added icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
33 changes: 33 additions & 0 deletions substitute.js
Original file line number Diff line number Diff line change
@@ -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
});

0 comments on commit 691960d

Please sign in to comment.