diff --git a/background.js b/background.js index c782616..f63738c 100644 --- a/background.js +++ b/background.js @@ -2,6 +2,14 @@ // console.log(request); // sendResponse({ farewell: "goodbye" }); // }); +let customSlogans = []; + +chrome.storage.sync.get("savedCustomSlogans", function(items) { + customSlogans = items.savedCustomSlogans; + updateUserBannedList(""); +}); + +const userBannedSlogansList = document.getElementById("userBannedSlogansList"); const bannedSlogansList = document.getElementById("bannedSlogansList"); const page1 = document.getElementById("page1"); @@ -9,6 +17,34 @@ const page2btn = document.getElementById("s_page2"); const page1btn = document.getElementById("s_page1"); const container = document.getElementById("container"); +const customSloganTextbox = document.getElementById("customSlogan"); +const addSlogan = document.getElementById("add"); + +customSloganTextbox.onkeyup = () => { + updateUserBannedList(customSloganTextbox.value); +}; + +addSlogan.onclick = () => { + const customSlogan = customSloganTextbox.value; + if (!customSlogans.includes(customSlogan)) { + customSlogans.push(customSlogan); + + chrome.storage.sync.set({ savedCustomSlogans: customSlogans }, function() { + updateUserBannedList(customSloganTextbox.value); + }); + } +}; + +function updateUserBannedList(filter) { + userBannedSlogansList.innerHTML = ""; + customSlogans.forEach((slogan, i) => { + if (slogan.includes(filter)) { + let sloganDOM = span(span(i + 1) + span(slogan) + button(i, "-")); + userBannedSlogansList.innerHTML += sloganDOM; + } + }); +} + page2btn.onclick = () => { page1.style.marginLeft = "-400px"; }; @@ -19,6 +55,9 @@ page1btn.onclick = () => { function span(text) { return "" + text + ""; } +function button(id, text) { + return ""; +} //get banned slogans chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { diff --git a/manifest.json b/manifest.json index 3dcff7b..b144788 100644 --- a/manifest.json +++ b/manifest.json @@ -14,5 +14,5 @@ "browser_action": { "default_popup": "popup.html" }, - "permissions": ["activeTab"] + "permissions": ["activeTab", "storage"] } diff --git a/popup.html b/popup.html index dc9887c..f6bed0b 100644 --- a/popup.html +++ b/popup.html @@ -28,11 +28,11 @@ display: inline-block; padding: 0 15px; } - #bannedSlogansList { + .list { overflow: auto; max-height: 200px; } - #bannedSlogansList > span { + .list > span { display: flex; width: 100%; overflow: hidden; @@ -40,18 +40,22 @@ padding: 5px 0; cursor: pointer; } - #bannedSlogansList > span > span { + .list > span > span { display: inline-block; } - #bannedSlogansList > span:nth-child(2n) { + .list > span:nth-child(2n) { background: rgb(34, 34, 34); } - #bannedSlogansList > span > span:first-child { + .list > span > span:first-child { flex-shrink: 0; width: 50px; text-align: center; margin-right: 10px; } + .list > span > button { + margin: auto; + margin-right: 10px; + } .pageBtn { display: block; width: 100%; @@ -75,16 +79,16 @@ > Go to word banning settings Banned slogans found on this webpage: -
+
Add your own banned slogans: - + -
+