Skip to content

Commit

Permalink
Laatuhesari
Browse files Browse the repository at this point in the history
  • Loading branch information
lalnuo committed Nov 11, 2020
0 parents commit 1782632
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# laatuhesari
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
console.log("Laatuhesari käynnistetty");

const forbiddenArticles = ["korona", "trump"];
const elementHasCorona = (node) =>
forbiddenArticles.some(word => (node.textContent || "").toLowerCase().indexOf(word) > 0)


const removeArticle = (domNode) => {
if (domNode.tagName === "ARTICLE") {
domNode.remove();
} else if (domNode.parentNode) {
removeArticle(domNode.parentNode);
}
};

const checkForCorona = (domNode) => {
if (domNode && elementHasCorona(domNode)) {
removeArticle(domNode);
}
if (domNode && domNode.childNodes) {
domNode.childNodes.forEach((x) => {
checkForCorona(x);
});
}
};

document.addEventListener("DOMNodeInserted", (event) => {
if (elementHasCorona(event.target)) {
checkForCorona(event.target);
}
});

checkForCorona(document);
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Laatuhesari",
"version": "1.0",
"description": "Filtteröi tietyn sanan sisältävät artikkelit hesarin etusivulta",
"manifest_version": 2,
"content_scripts": [{
"js": ["index.js"],
"matches": ["https://www.hs.fi/"]
}]
}

0 comments on commit 1782632

Please sign in to comment.