Skip to content

Commit 79cbaa5

Browse files
authored
Merge pull request #55 from richardfrost/fix_removing_default_words
Fix removing default words
2 parents ae8d499 + 21c7b2f commit 79cbaa5

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

filter.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ var defaults = {
99
"preserveFirst": false,
1010
"showCounter": true,
1111
"substitutionMark": true,
12-
"words": {
13-
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
14-
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
15-
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
16-
"bitch": {"matchMethod": 1, "words": ["jerk"] },
17-
"cunt": {"matchMethod": 1, "words": ["explative"] },
18-
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
19-
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
20-
"piss": {"matchMethod": 1, "words": ["pee"] },
21-
"pissed": {"matchMethod": 0, "words": ["ticked"] },
22-
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
23-
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
24-
"tits": {"matchMethod": 1, "words": ["explative"] },
25-
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
26-
}
12+
"words": {}
2713
};
14+
var defaultWords = {
15+
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
16+
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
17+
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
18+
"bitch": {"matchMethod": 1, "words": ["jerk"] },
19+
"cunt": {"matchMethod": 1, "words": ["explative"] },
20+
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
21+
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
22+
"piss": {"matchMethod": 1, "words": ["pee"] },
23+
"pissed": {"matchMethod": 0, "words": ["ticked"] },
24+
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
25+
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
26+
"tits": {"matchMethod": 1, "words": ["explative"] },
27+
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
28+
}
2829
var censorCharacter, censorFixedLength, defaultSubstitutions, disabledDomains, filterMethod, globalMatchMethod, matchMethod, preserveFirst, showCounter, substitutionMark, words, wordList;
2930
var wordRegExps = [];
3031
var whitespaceRegExp = new RegExp('\\s');
@@ -96,6 +97,11 @@ function cleanPage() {
9697
return false;
9798
}
9899

100+
// If no words are specified use defaultWords
101+
if (Object.keys(storage.words).length === 0 && storage.words.constructor === Object) {
102+
storage.words = defaultWords;
103+
}
104+
99105
// Load settings and setup environment
100106
censorCharacter = storage.censorCharacter;
101107
censorFixedLength = storage.censorFixedLength;

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"short_name": "Profanity Filter",
44
"author": "phermium",
55
"manifest_version": 2,
6-
"version": "1.0.1",
6+
"version": "1.0.2",
77
"description": "Hide offensive words on the webpages you visit",
88
"icons": {
99
"16": "icons/icon16.png",

options.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ var defaults = {
99
"preserveFirst": false,
1010
"showCounter": true,
1111
"substitutionMark": true,
12-
"words": {
13-
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
14-
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
15-
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
16-
"bitch": {"matchMethod": 1, "words": ["jerk"] },
17-
"cunt": {"matchMethod": 1, "words": ["explative"] },
18-
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
19-
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
20-
"piss": {"matchMethod": 1, "words": ["pee"] },
21-
"pissed": {"matchMethod": 0, "words": ["ticked"] },
22-
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
23-
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
24-
"tits": {"matchMethod": 1, "words": ["explative"] },
25-
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
26-
}
12+
"words": {}
13+
};
14+
var defaultWords = {
15+
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
16+
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
17+
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
18+
"bitch": {"matchMethod": 1, "words": ["jerk"] },
19+
"cunt": {"matchMethod": 1, "words": ["explative"] },
20+
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
21+
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
22+
"piss": {"matchMethod": 1, "words": ["pee"] },
23+
"pissed": {"matchMethod": 0, "words": ["ticked"] },
24+
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
25+
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
26+
"tits": {"matchMethod": 1, "words": ["explative"] },
27+
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
2728
};
2829
var filterMethods = ["Censor", "Substitute", "Remove"];
2930
var matchMethods = ["Exact Match", "Partial Match", "Whole Match", "Per-Word Match"];
@@ -154,7 +155,7 @@ function migrateWordList() {
154155
if (word != "") {
155156
if (!arrayContains(Object.keys(config.words), word)) {
156157
console.log('Migrating word: ' + word);
157-
config.words[word] = {"matchMethod": 1, "words": []};
158+
config.words[word] = {"matchMethod": 0, "words": []};
158159
} else {
159160
console.log('Word already in list: ' + word);
160161
}
@@ -198,6 +199,11 @@ function populateOptions() {
198199
chrome.storage.sync.get(defaults, function(settings) {
199200
config = settings; // Make config globally available
200201
migrateWordList(); // TODO: Migrate wordList
202+
if (Object.keys(config.words).length === 0 && config.words.constructor === Object) {
203+
config.words = defaultWords;
204+
saveOptions(null, config);
205+
return false;
206+
}
201207

202208
// Show/hide censor options and word substitutions based on filter method
203209
dynamicList(filterMethods, 'filterMethodSelect');
@@ -332,7 +338,6 @@ function wordAdd(event) {
332338
if (!arrayContains(Object.keys(config.words), word)) {
333339
config.words[word] = {"matchMethod": 1, "words": []};
334340
saveOptions(event, config);
335-
dynamicList(Object.keys(config.words), 'wordSelect', 'Words to Filter');
336341
document.getElementById('wordText').value = "";
337342
} else {
338343
updateStatus('Word already in list.', true, 3000);
@@ -360,7 +365,6 @@ function wordRemove(event) {
360365
if (word != "") {
361366
delete config.words[word];
362367
saveOptions(event, config);
363-
dynamicList(Object.keys(config.words), 'wordSelect', 'Words to Filter');
364368
}
365369
}
366370

0 commit comments

Comments
 (0)