Skip to content

Commit

Permalink
Merge pull request #55 from richardfrost/fix_removing_default_words
Browse files Browse the repository at this point in the history
Fix removing default words
  • Loading branch information
richardfrost authored Jan 30, 2018
2 parents ae8d499 + 21c7b2f commit 79cbaa5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
36 changes: 21 additions & 15 deletions filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ var defaults = {
"preserveFirst": false,
"showCounter": true,
"substitutionMark": true,
"words": {
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"bitch": {"matchMethod": 1, "words": ["jerk"] },
"cunt": {"matchMethod": 1, "words": ["explative"] },
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
"piss": {"matchMethod": 1, "words": ["pee"] },
"pissed": {"matchMethod": 0, "words": ["ticked"] },
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
"tits": {"matchMethod": 1, "words": ["explative"] },
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
}
"words": {}
};
var defaultWords = {
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"bitch": {"matchMethod": 1, "words": ["jerk"] },
"cunt": {"matchMethod": 1, "words": ["explative"] },
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
"piss": {"matchMethod": 1, "words": ["pee"] },
"pissed": {"matchMethod": 0, "words": ["ticked"] },
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
"tits": {"matchMethod": 1, "words": ["explative"] },
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
}
var censorCharacter, censorFixedLength, defaultSubstitutions, disabledDomains, filterMethod, globalMatchMethod, matchMethod, preserveFirst, showCounter, substitutionMark, words, wordList;
var wordRegExps = [];
var whitespaceRegExp = new RegExp('\\s');
Expand Down Expand Up @@ -96,6 +97,11 @@ function cleanPage() {
return false;
}

// If no words are specified use defaultWords
if (Object.keys(storage.words).length === 0 && storage.words.constructor === Object) {
storage.words = defaultWords;
}

// Load settings and setup environment
censorCharacter = storage.censorCharacter;
censorFixedLength = storage.censorFixedLength;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "Profanity Filter",
"author": "phermium",
"manifest_version": 2,
"version": "1.0.1",
"version": "1.0.2",
"description": "Hide offensive words on the webpages you visit",
"icons": {
"16": "icons/icon16.png",
Expand Down
40 changes: 22 additions & 18 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ var defaults = {
"preserveFirst": false,
"showCounter": true,
"substitutionMark": true,
"words": {
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"bitch": {"matchMethod": 1, "words": ["jerk"] },
"cunt": {"matchMethod": 1, "words": ["explative"] },
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
"piss": {"matchMethod": 1, "words": ["pee"] },
"pissed": {"matchMethod": 0, "words": ["ticked"] },
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
"tits": {"matchMethod": 1, "words": ["explative"] },
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
}
"words": {}
};
var defaultWords = {
"ass": {"matchMethod": 0, "words": ["butt", "tail"] },
"asshole": {"matchMethod": 1, "words": ["butthole", "jerk"] },
"bastard": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"bitch": {"matchMethod": 1, "words": ["jerk"] },
"cunt": {"matchMethod": 1, "words": ["explative"] },
"damn": {"matchMethod": 1, "words": ["dang", "darn"] },
"fuck": {"matchMethod": 1, "words": ["freak", "fudge"] },
"piss": {"matchMethod": 1, "words": ["pee"] },
"pissed": {"matchMethod": 0, "words": ["ticked"] },
"slut": {"matchMethod": 1, "words": ["imperfect", "impure"] },
"shit": {"matchMethod": 1, "words": ["crap", "crud", "poop"] },
"tits": {"matchMethod": 1, "words": ["explative"] },
"whore": {"matchMethod": 1, "words": ["harlot", "tramp"] }
};
var filterMethods = ["Censor", "Substitute", "Remove"];
var matchMethods = ["Exact Match", "Partial Match", "Whole Match", "Per-Word Match"];
Expand Down Expand Up @@ -154,7 +155,7 @@ function migrateWordList() {
if (word != "") {
if (!arrayContains(Object.keys(config.words), word)) {
console.log('Migrating word: ' + word);
config.words[word] = {"matchMethod": 1, "words": []};
config.words[word] = {"matchMethod": 0, "words": []};
} else {
console.log('Word already in list: ' + word);
}
Expand Down Expand Up @@ -198,6 +199,11 @@ function populateOptions() {
chrome.storage.sync.get(defaults, function(settings) {
config = settings; // Make config globally available
migrateWordList(); // TODO: Migrate wordList
if (Object.keys(config.words).length === 0 && config.words.constructor === Object) {
config.words = defaultWords;
saveOptions(null, config);
return false;
}

// Show/hide censor options and word substitutions based on filter method
dynamicList(filterMethods, 'filterMethodSelect');
Expand Down Expand Up @@ -332,7 +338,6 @@ function wordAdd(event) {
if (!arrayContains(Object.keys(config.words), word)) {
config.words[word] = {"matchMethod": 1, "words": []};
saveOptions(event, config);
dynamicList(Object.keys(config.words), 'wordSelect', 'Words to Filter');
document.getElementById('wordText').value = "";
} else {
updateStatus('Word already in list.', true, 3000);
Expand Down Expand Up @@ -360,7 +365,6 @@ function wordRemove(event) {
if (word != "") {
delete config.words[word];
saveOptions(event, config);
dynamicList(Object.keys(config.words), 'wordSelect', 'Words to Filter');
}
}

Expand Down

0 comments on commit 79cbaa5

Please sign in to comment.