From 3cd13d137669e85f1620d17c307efef815431570 Mon Sep 17 00:00:00 2001 From: blackstormx Date: Tue, 28 Jul 2020 23:14:24 +0400 Subject: [PATCH] main commit --- background.js | 0 content.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ logo.png | Bin 0 -> 16768 bytes manifest.json | 19 +++++++++ popup.html | 26 +++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 background.js create mode 100644 content.js create mode 100644 logo.png create mode 100644 manifest.json create mode 100644 popup.html diff --git a/background.js b/background.js new file mode 100644 index 0000000..e69de29 diff --git a/content.js b/content.js new file mode 100644 index 0000000..0f62801 --- /dev/null +++ b/content.js @@ -0,0 +1,106 @@ +const body = document.body; + +const bannedWord = "*Banned by StopSlogan*"; + +const slogans = {}; +let slogansKeys = []; +const bannedSlogans = []; + +// const url = "https://en.wikipedia.org/wiki/List_of_political_slogans"; +const url = + "https://en.wikipedia.org/w/api.php?" + + new URLSearchParams({ + origin: "*", + + action: "parse", + page: "List_of_political_slogans", + format: "json" + }); +//en.wikipedia.org/w/api.php?action=parse&format=json&origin=*&page=Most%20common%20words%20in%20Spanish' + +function parseNode(startNode) { + if (startNode.tagName == "LI") { + const key = startNode.innerText.toLowerCase(); + slogans[key] = true; + slogansKeys.push(key); + } + startNode.childNodes.forEach(node => { + parseNode(node); + }); +} + +const callback = function(mutationsList, observer) { + // Use traditional 'for loops' for IE 11 + for (let mutation of mutationsList) { + if (mutation.type === "childList") { + const node = mutation.target; + checkNodeRecursively(node); + } + } +}; + +fetch(url) + .then(response => response.json()) + .then(parsed => parsed.parse.text) + .then(text => { + const domParser = new DOMParser(); + let doc = domParser.parseFromString(text["*"], "text/html"); + parseNode(doc); + checkNodeRecursively(body); + const observer = new MutationObserver(callback); + observer.observe(body, { + childList: true, + subtree: true + }); + }); + +function checkNode(startNode) { + if (startNode.nodeType == Node.TEXT_NODE) { + const value = startNode.nodeValue.toLowerCase(); + if (deepCheck(value)) { + startNode.nodeValue = "*Banned by StopSlogan*"; + bannedSlogans.push(value); + } + } else { + if (startNode.nodeType == Node.ELEMENT_NODE) { + if (startNode.tagName == "INPUT" || startNode.tagName == "TEXTAREA") { + if (deepCheck(startNode.value)) { + startNode.value = bannedWord; + } + } else { + if (startNode.childNodes.length == 0) { + if (deepCheck(startNode.innerText)) { + startNode.innerText = bannedWord; + } + } + } + } + } +} + +function deepCheck(text) { + if (text == bannedWord || !text) { + return false; + } + text = text.toLowerCase(); + + if (slogans[text]) { + return true; + } + for (var i = 0; i < slogansKeys.length; i++) { + const key = slogansKeys[i]; + if (text.includes(key)) { + return true; + } + } + return false; + //TODO: Levenshtein Distance Algorithm +} + +function checkNodeRecursively(startNode) { + checkNode(startNode); + + startNode.childNodes.forEach(node => { + checkNodeRecursively(node); + }); +} diff --git a/logo.png b/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..546064ec0f784195477042e155b5d70fd23875dc GIT binary patch literal 16768 zcmeI3dsGu=7QhDsKG0UFFHl=U1f)usOr9i$P)rbl1`)ynEw9OB0wYN#CV>D2Dnzlg zYqyjl7F4u~OV#=)Yr8EKX%*L6E52&2eWa_|X)z^#ajNx` zsuF%nO-ii#W1?YYNy$fn{`*4+>&xRA40%DmGJG6^flOd9>``&K&TBWvb#BzFJffZG zGkK|Uc?8jiVYd{Aqsw#!i^@y4)YsRSBGJWhI~JPI70TtteWjUc=Hg}H#mh9x<(@?6 zvyYD^j3_D;SWp}ePR z?fZ(5iJ2Ea+j96+YsYF{MdzsMIbTdOs@grIanktw)p>I}#&xQ`ufCifw0X{6`N@P^ zFU9USIq`Cu*VKvwZ(e>g{cu3}%<}Y#hF4#&lm=9RY`*wBeNOH;wg_{`b1 zix~&qyYH{O+fp9B*lt^$GNH)l#1!A@*wm?Bsa`x@?$WRA?(ZtT*|zse+3SM0L}$d@ zATF=*2VMGcw5_piPvCj=o!v=IemkuRU)Fj)IQH6(RKef(r{%<7pDp}Z@HxNEP?bGj zA9msCZxYTHeUP|+&%W+ggRwOs!2d4+PPBlq~F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8lbeVydzna7oC*L6`~hI49RRwziSso8$l(CM&lvz9Sq}iy@z>H@7Xg6V z4W%Mnop-_dYHC!a+my1poAB5iQ z%Z*!CF;6q+U2Cgl`Hx!hw*KUlpk3;7XM^UKs;raucjZD=tk9dEUB0#9(DP|qE2|0v z6u#HXD?d%@_~w_5``)}=v~^h-=N3;nPYBpU<_DTa$E0<>^8VrYwEv_uzqIDu4QA)n zt+g}x9Xs3qb-FcuUiHDI%xu}!St~_%u6>t^bc7u(eRlf=^Lvd9<0-|qbB%thVl#Hg zLOo8LuFEN0k>%<0@{r3O3wx9c{YMWQR=ax>-3th`oy<^&o zD%1_~h4z~GidT*Wtcw0T_sFb3@3xqSUyspmnK~A^bm^&sZr&}&L<=^Y={)tzmXgQ` z6>F;(O9K?6fis2a**_fFKgsvEE0;3B*fnG3qJZDtw)LCZf4yRmy!eE6)tIk+qvvkD z<92?@g@*kYEBiKY%ronKM$OWdj@zEE6nx*QOPT)G58qe3gC2_b>ES"], + "js": ["content.js"] + } + ], + "background": { + "scripts": ["scripts/background.js"], + "persistent": false + }, + "browser_action": { + "default_popup": "popup.html" + }, + "permissions": ["activeTab"] +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..844e21f --- /dev/null +++ b/popup.html @@ -0,0 +1,26 @@ + + + + Stop Slogan + + + +
+ Currently banned slogans: + +
+
+ +