-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1782632
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# laatuhesari |
This file contains 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
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); |
This file contains 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
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/"] | ||
}] | ||
} |