Skip to content

Commit af57f83

Browse files
committed
Add option for saving
1 parent 4d08f90 commit af57f83

6 files changed

+66
-23
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# cens█r
22
This is a simple app to test out how chrome extensions work. It will block out words that you choose.
3+
![Screenshot](http://i.imgur.com/FVyKkvi)

browser_action.html

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
<!doctype html>
2-
<style type="text/css">
3-
#mainPopup {
4-
padding: 10px;
5-
height: 200px;
6-
width: 400px;
7-
font-family: Helvetica, Ubuntu, Arial, sans-serif;
8-
}
9-
h1 {
10-
font-size: 2em;
11-
}
12-
</style>
13-
14-
<div id="mainPopup">
15-
<h1>Hello extensionizr!</h1>
16-
<p>To shut this popup down, edit the manifest file and remove the "default popup" key. To edit it, just edit ext/browser_action/browser_action.html. The CSS is there, too.</p>
17-
</div>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>My Test Extension Options</title>
5+
<style type="text/css">
6+
#words {
7+
padding: 10px;
8+
height: 200px;
9+
width: 400px;
10+
font-family: Helvetica, Ubuntu, Arial, sans-serif;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<h1>cens&#x2588;r</h1>
16+
Add a words or phrases separated by commas and hit Save to begin the censoring.
17+
<div id="status"></div>
18+
<textarea id="words" placeholder="Type in the words you want blocked out here. Each, word, or, phrase, separated, by, a, comma."></textarea>
19+
<button id="save">Save</button>
20+
<script src="browser_action.js"></script>
21+
</body>
22+
</html>

browser_action.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Saves options to chrome.storage
2+
function save_options() {
3+
var textBox = document.getElementById('words').value;
4+
chrome.storage.sync.set({
5+
words: textBox,
6+
}, function() {
7+
// Update status to let user know options were saved.
8+
var status = document.getElementById('status');
9+
status.textContent = 'Options saved.';
10+
setTimeout(function() {
11+
status.textContent = '';
12+
}, 750);
13+
});
14+
}
15+
16+
// Restores select box and checkbox state using the preferences
17+
// stored in chrome.storage.
18+
function restore_options() {
19+
// Use default value color = 'red' and likesColor = true.
20+
chrome.storage.sync.get({
21+
words: ""
22+
}, function(items) {
23+
document.getElementById('words').value = items.words;
24+
});
25+
}
26+
document.addEventListener('DOMContentLoaded', restore_options);
27+
document.getElementById('save').addEventListener('click',
28+
save_options);
File renamed without changes.

manifest.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
"description": "Block out words of your choice.",
44
"version": "0.0.1",
55
"permissions": [
6-
"activeTab"
6+
"activeTab",
7+
"storage"
78
],
89
"browser_action": {
9-
"default_title": "Block out words of your choice.",
10-
"default_popup": "browser_action.html"
10+
"default_title": "Block out words of your choice."
1111
},
1212
"content_scripts": [
1313
{
1414
"matches": ["http://*/*", "https://*/*"],
15-
"js": ["scripts/findAndReplaceDOMText.js", "replace.js"],
15+
"js": ["findAndReplaceDOMText.js", "replace.js"],
1616
"run_at": "document_end"
1717
}
1818
],
19-
"manifest_version": 2
19+
"manifest_version": 2,
20+
"options_page": "browser_action.html"
2021
}

replace.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
element=document.createElement('span');
22
element.setAttribute("style", "background-color:black;color:black;");
3-
findAndReplaceDOMText(document.body, {find: 'match', wrap: element});
3+
chrome.storage.sync.get({
4+
words: ""
5+
}, function(items) {
6+
var words = items.words.split(",");
7+
for (var word in words) {
8+
console.log(items.words);
9+
findAndReplaceDOMText(document.body, {find: words[word], wrap: element});
10+
}
11+
});

0 commit comments

Comments
 (0)