Skip to content

Commit

Permalink
Fix bug keep adding restore button
Browse files Browse the repository at this point in the history
  • Loading branch information
dthung1602 committed Jun 19, 2022
1 parent e0026dc commit 2f12ac2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion manifest-v2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "TheSpamminator",
"version": "1.2.0",
"version": "1.2.1",
"description": "Remove banger alert spams from comment section of mangakakalot & manganato",
"icons": {
"16": "images/logo/spam-logo-16.png",
Expand Down
2 changes: 1 addition & 1 deletion manifest-v3.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "TheSpamminator",
"version": "1.2.0",
"version": "1.2.1",
"description": "Remove banger alert spams from comment section of mangakakalot & manganato",
"icons": {
"16": "images/logo/spam-logo-16.png",
Expand Down
2 changes: 1 addition & 1 deletion popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</section>
<section id="about" class="hidden">
<div id="version">
<span>Version 1.2.0</span>
<span>Version 1.2.1</span>
</div>
<div id="what-new">
<a href="https://github.com/dthung1602/the-spamminator/releases" target="_blank">
Expand Down
34 changes: 22 additions & 12 deletions scripts/clean-spams.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function createRestoreButton(node, restoreKey) {
}

function createBlackListButton(spamDomain) {
const button = htmlToElement(`<span class="additional-button">✖ Blacklist domain</span>`);
const button = htmlToElement(`<span class="additional-button" title="Add this domain to The Spamminator's blacklist">✖ Blacklist domain</span>`);
button.addEventListener("click", async () => {
let { banDomains } = await browser.storage.local.get(["banDomains"]);
banDomains = Array.from(new Set([...banDomains, spamDomain]));
Expand Down Expand Up @@ -158,27 +158,37 @@ async function cleanSpams() {
]);

const action = actionMapping.get(cleanSpamAction);
const filter = (node) => containBanDomain(node, banDomains);
const filterContainSpam = (node) => containBanDomain(node, banDomains);

let spamCount = 0;
const count = () => spamCount += 1;

// replace links in nested comments
const performAction = (node) => {
node.classList.add("spam-free");
action(node);
}

// first, find the nested spam comments
// if the outer comment & the nested comment belongs to the same account, perform action on the outer comment
// the nested spammer comment is handled later
const linksInNestedComments = window.document.querySelectorAll(".UFIImageBlockContent .UFIImageBlockContent ._5mdd a");
Array.from(linksInNestedComments)
.filter(filter)
.map((node) => getAncestor(node, 11).querySelector("._3-8m"))
.map(action)
.filter(filterContainSpam)
.map((node) => {
const spammerName = getAncestor(node, 5).querySelector(".UFICommentActorName").text;
const outerComment = getAncestor(node, 11);
const outerCommenterName = outerComment.querySelector(".UFICommentActorName").text;
return spammerName === outerCommenterName ? outerComment.querySelector("._3-8m") : null;
})
.filter(Boolean)
.map(performAction)
.map(count);

// replace text spams in comments & nested comments
// find all spam comments, nested or not, and perform actions on them
const uncheckedComments = window.document.querySelectorAll("._3-8m:not(.spam-free)");
Array.from(uncheckedComments)
.filter(filter)
.map((node) => {
node.classList.add("spam-free");
action(node)
})
.filter(filterContainSpam)
.map(performAction)
.map(count);

console.log(`Found ${spamCount} spams`);
Expand Down

0 comments on commit 2f12ac2

Please sign in to comment.