Skip to content

Commit ae8d499

Browse files
authored
Merge pull request #53 from richardfrost/migrate_wordlist
Migrate wordlist
2 parents 0b34d73 + 7ed960e commit ae8d499

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

eventPage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ chrome.runtime.onInstalled.addListener(function(details){
88
} else if (details.reason == "update") {
99
// var thisVersion = chrome.runtime.getManifest().version;
1010
// console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");
11+
12+
// TODO: Migrate wordList - Open options page to show new features
13+
chrome.runtime.openOptionsPage();
1114
}
1215
});
1316

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.0",
6+
"version": "1.0.1",
77
"description": "Hide offensive words on the webpages you visit",
88
"icons": {
99
"16": "icons/icon16.png",

options.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ function exportConfig() {
118118
});
119119
}
120120

121+
function filterMethodSelect(event) {
122+
config.filterMethod = document.getElementById('filterMethodSelect').selectedIndex;
123+
saveOptions(event, config);
124+
}
125+
121126
function globalMatchMethod(event) {
122127
var selectedIndex = document.getElementById('globalMatchMethodSelect').selectedIndex;
123128
config.globalMatchMethod = selectedIndex;
@@ -133,9 +138,39 @@ function importConfig(event) {
133138
}
134139
}
135140

136-
function filterMethodSelect(event) {
137-
config.filterMethod = document.getElementById('filterMethodSelect').selectedIndex;
138-
saveOptions(event, config);
141+
// TODO: Migrate wordList to new words object
142+
function migrateWordList() {
143+
chrome.storage.sync.get('wordList', function(storage) {
144+
var wordListStr = storage.wordList;
145+
146+
if (wordListStr != undefined && wordListStr != '') {
147+
var word = '';
148+
var wordList = wordListStr.split(',');
149+
150+
try {
151+
// Migrate to new words object
152+
for (i = 0; i < wordList.length; i++) {
153+
word = wordList[i];
154+
if (word != "") {
155+
if (!arrayContains(Object.keys(config.words), word)) {
156+
console.log('Migrating word: ' + word);
157+
config.words[word] = {"matchMethod": 1, "words": []};
158+
} else {
159+
console.log('Word already in list: ' + word);
160+
}
161+
}
162+
}
163+
164+
// Remove wordList if successful
165+
console.log(wordListStr, wordList);
166+
saveOptions(undefined, config);
167+
chrome.storage.sync.remove('wordList');
168+
}
169+
catch(error) {
170+
console.log('Error: Aborting wordList migration!', error);
171+
}
172+
}
173+
});
139174
}
140175

141176
// Switching Tabs
@@ -162,6 +197,7 @@ function openTab(event) {
162197
function populateOptions() {
163198
chrome.storage.sync.get(defaults, function(settings) {
164199
config = settings; // Make config globally available
200+
migrateWordList(); // TODO: Migrate wordList
165201

166202
// Show/hide censor options and word substitutions based on filter method
167203
dynamicList(filterMethods, 'filterMethodSelect');

0 commit comments

Comments
 (0)