Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyadetman committed Apr 15, 2019
1 parent c4f5235 commit c0367bc
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 28 deletions.
14 changes: 14 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
document.addEventListener('DOMNodeInserted', () => {
chrome.storage.sync.get(["words"], res => {
const currentWords = "{}" !== JSON.stringify(res) ? JSON.parse(res.words) : [];
const allPosts = Array.from(document.getElementsByClassName('_5jmm'));
allPosts.map(post => {
currentWords.forEach(word => {
if (post.textContent.includes(word)) {
console.log(word)
post.style.display = 'none';
}
})
})
});
})
23 changes: 20 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
"name": "Mute Words on Facebook",
"version": "1.0",
"description": "Mute words on facebook newsfeed!",
"permissions": ["storage"],
"permissions": [
"storage",
"tabs",
"*://*.facebook.com/*"
],
"background": {
"scripts": ["background.js"],
"scripts": [
"background.js"
],
"persistent": false
},
"content_scripts": [
{
"matches": [
"https://www.facebook.com/",
"*://*.facebook.com/*"
],
"js": [
"content.js"
]
}
],
"browser_action": {
"default_popup": "popup.html"
},
"manifest_version": 2
}
}
33 changes: 18 additions & 15 deletions popup.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>

<body>
<input placeholder="word" id="wordinput" />
<p id="te"></p>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>

<script type="text/javascript" src="popup.js"></script>
</body>
</html>
<body>
<input placeholder="word" id="wordinput" />
<ul id="currentwords"></ul>
<button id="clearall">Clear</button>

<script type="text/javascript" src="popup.js"></script>
</body>

</html>
32 changes: 22 additions & 10 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
listWords();

document.getElementById("wordinput").addEventListener("keypress", e => {
if (e.key === "Enter") {
addWord(document.getElementById("wordinput").value);
listWords();
}
});

document.getElementById('clearall').addEventListener('click', e => {
clearAll()
})

function addWord(newWord) {
chrome.storage.sync.get(["words"], result => {
console.log(newWord);
//' '_5jmm''
//document.getElementsByClassName('_5jmm')[0].textContent.includes('1945') ? document.getElementsByClassName('_5jmm')[0].style.display = 'none' : console.log('1')
//_5pat
//_5pbx
const newWordsObject = "{}" === JSON.stringify(result) ? { words: [] } : result;
const newWords = newWordsObject.words.length > 0 ? JSON.parse(newWordsObject.words) : newWordsObject.words;
//' '_5jmm'' //_5pat //_5pbx
chrome.storage.sync.set({
words: JSON.stringify([...JSON.parse(result), newWord])
});
words: JSON.stringify([...newWords, newWord])
}, listWords);
});
}

function removeWord() {}
function removeWord() {
/* TODO */
}

function clearAll() {
chrome.storage.sync.clear(listWords);
}

function listWords() {
chrome.storage.sync.get(["words"], res => {
console.log(res);
document.getElementById("te").innerHTML = res;
const currentWords = "{}" !== JSON.stringify(res) ? JSON.parse(res.words) : [];
let listItems = '';
currentWords.map(itm => listItems += `<li>${itm}</li>`)
document.getElementById("currentwords").innerHTML = listItems;
});
}

0 comments on commit c0367bc

Please sign in to comment.