Skip to content

Commit

Permalink
Merge pull request #53 from richardfrost/migrate_wordlist
Browse files Browse the repository at this point in the history
Migrate wordlist
  • Loading branch information
richardfrost authored Jan 29, 2018
2 parents 0b34d73 + 7ed960e commit ae8d499
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions eventPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ chrome.runtime.onInstalled.addListener(function(details){
} else if (details.reason == "update") {
// var thisVersion = chrome.runtime.getManifest().version;
// console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");

// TODO: Migrate wordList - Open options page to show new features
chrome.runtime.openOptionsPage();
}
});

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.0",
"version": "1.0.1",
"description": "Hide offensive words on the webpages you visit",
"icons": {
"16": "icons/icon16.png",
Expand Down
42 changes: 39 additions & 3 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ function exportConfig() {
});
}

function filterMethodSelect(event) {
config.filterMethod = document.getElementById('filterMethodSelect').selectedIndex;
saveOptions(event, config);
}

function globalMatchMethod(event) {
var selectedIndex = document.getElementById('globalMatchMethodSelect').selectedIndex;
config.globalMatchMethod = selectedIndex;
Expand All @@ -133,9 +138,39 @@ function importConfig(event) {
}
}

function filterMethodSelect(event) {
config.filterMethod = document.getElementById('filterMethodSelect').selectedIndex;
saveOptions(event, config);
// TODO: Migrate wordList to new words object
function migrateWordList() {
chrome.storage.sync.get('wordList', function(storage) {
var wordListStr = storage.wordList;

if (wordListStr != undefined && wordListStr != '') {
var word = '';
var wordList = wordListStr.split(',');

try {
// Migrate to new words object
for (i = 0; i < wordList.length; i++) {
word = wordList[i];
if (word != "") {
if (!arrayContains(Object.keys(config.words), word)) {
console.log('Migrating word: ' + word);
config.words[word] = {"matchMethod": 1, "words": []};
} else {
console.log('Word already in list: ' + word);
}
}
}

// Remove wordList if successful
console.log(wordListStr, wordList);
saveOptions(undefined, config);
chrome.storage.sync.remove('wordList');
}
catch(error) {
console.log('Error: Aborting wordList migration!', error);
}
}
});
}

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

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

0 comments on commit ae8d499

Please sign in to comment.