[go: nahoru, domu]

Skip to content

Commit

Permalink
Removed redundant context menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
SerChirag committed Jul 16, 2018
1 parent 401c257 commit a2afcc4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 331 deletions.
Binary file removed lib/assets/img/bookmark.png
Binary file not shown.
Binary file removed lib/assets/img/volume.png
Binary file not shown.
164 changes: 1 addition & 163 deletions lib/scripts/eventPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { localData } from './utils/defaultStorage';

var contextMenu = new ContextMenu(),
translatedWords = {},
activeContextMenuIds = ['speakTheWord', 'blacklistWord', 'blacklistWebsite', 'saveTranslationToDictionary', 'searchForSimilarWords', 'wordUsageExamples', 'difficultyBucketFeatures', 'markAsLearnt', 'translateSentence', 'whitelistWebsite', 'visualHints'];
activeContextMenuIds = ['speakTheWord', 'blacklistWebsite', 'searchForSimilarWords', 'translateSentence', 'whitelistWebsite'];

/**
* Set up default data and store it in `chrome.storage.localData`
Expand All @@ -28,12 +28,6 @@ function setup() {
'contexts': ['selection'],
'id': 'speakTheWord'
});
chrome.contextMenus.create({
'title': 'Blacklist Selected Word',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'blacklistWord'
});
chrome.contextMenus.create({
'title': 'Blacklist Website',
'parentId': 'parent',
Expand All @@ -46,12 +40,6 @@ function setup() {
'contexts': ['page', 'selection'],
'id': 'whitelistWebsite'
});
chrome.contextMenus.create({
'title': 'Save Translation to Dictionary',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'saveTranslationToDictionary'
});
chrome.contextMenus.create({
'title': 'Search For Similar Words',
'parentId': 'parent',
Expand Down Expand Up @@ -82,78 +70,12 @@ function setup() {
'contexts': ['selection'],
'id': 'searchForSimilarWordsOnThesaurus'
});
chrome.contextMenus.create({
'title': 'Show Word Usage Examples',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'wordUsageExamples'
});
chrome.contextMenus.create({
'title': 'yourdictionary.com',
'parentId': 'wordUsageExamples',
'contexts': ['selection'],
'id': 'wordUsageExamplesYourDictionary'
});
chrome.contextMenus.create({
'title': 'use-in-a-sentence.com',
'parentId': 'wordUsageExamples',
'contexts': ['selection'],
'id': 'wordUsageExamplesUseInASentence'
});
chrome.contextMenus.create({
'title': 'manythings.org',
'parentId': 'wordUsageExamples',
'contexts': ['selection'],
'id': 'wordUsageExamplesManyThings'
});
chrome.contextMenus.create({
'title': 'Add To Difficulty Bucket',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'difficultyBucketFeatures'
});
chrome.contextMenus.create({
'title': 'Easy',
'parentId': 'difficultyBucketFeatures',
'contexts': ['selection'],
'id': 'addToDifficultyBucketEasy'
});
chrome.contextMenus.create({
'title': 'Normal',
'parentId': 'difficultyBucketFeatures',
'contexts': ['selection'],
'id': 'addToDifficultyBucketNormal'
});
chrome.contextMenus.create({
'title': 'Hard',
'parentId': 'difficultyBucketFeatures',
'contexts': ['selection'],
'id': 'addToDifficultyBucketHard'
});
chrome.contextMenus.create({
'title': 'Mark as Learnt',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'markAsLearnt'
});
chrome.contextMenus.create({
'title': 'Translate Sentence',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'translateSentence'
});
chrome.contextMenus.create({
'title': 'Remove From Bucket',
'parentId': 'difficultyBucketFeatures',
'contexts': ['selection'],
'id': 'removeFromDifficultyBucket'
});
chrome.contextMenus.create({
'title': 'Show Visual Hints',
'parentId': 'parent',
'contexts': ['selection'],
'id': 'visualHints'
});
}

/**
Expand Down Expand Up @@ -250,9 +172,6 @@ function contextMenuClickHandler(info, tab) {
setContextMenus(false);
setWhitelist(true);
break;
case 'blacklistWord':
contextMenu.addWordToBlacklist(info.selectionText);
break;
case 'searchForSimilarWordsOnThesaurus':
contextMenu.searchForSimilarWords(info.selectionText, 'thesaurus');
break;
Expand All @@ -270,63 +189,6 @@ function contextMenuClickHandler(info, tab) {
contextMenu.speakTheWord();
});
break;
case 'addToDifficultyBucketEasy':
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { type: 'getTranslatedWords' }, (response) => {
if (response) {
contextMenu.addToDifficultyBucket(info.selectionText, 'e', response.translatedWords);
}
});
});
break;
case 'addToDifficultyBucketNormal':
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { type: 'getTranslatedWords' }, (response) => {
if (response) {
contextMenu.addToDifficultyBucket(info.selectionText, 'n', response.translatedWords);
}
});
});
break;
case 'addToDifficultyBucketHard':
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { type: 'getTranslatedWords' }, (response) => {
if (response) {
contextMenu.addToDifficultyBucket(info.selectionText, 'h', response.translatedWords);
}
});
});
break;
case 'removeFromDifficultyBucket':
contextMenu.removeFromDifficultyBucket(info.selectionText);
break;
case 'wordUsageExamplesYourDictionary':
contextMenu.searchForWordUsageExamples(info.selectionText, 'yourdictionary.com');
break;
case 'wordUsageExamplesManyThings':
contextMenu.searchForWordUsageExamples(info.selectionText, 'manythings.org');
break;
case 'wordUsageExamplesUseInASentence':
contextMenu.searchForWordUsageExamples(info.selectionText, 'use-in-a-sentence.com');
break;
case 'markAsLearnt':
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { type: 'getTranslatedWords' }, function(response) {
if (response) {
contextMenu.markWordAsLearnt(info.selectionText, response.translatedWords);
}
});
});
break;
case 'translateSentence':
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
Expand All @@ -348,35 +210,11 @@ function contextMenuClickHandler(info, tab) {
});
});
break;
case 'saveTranslationToDictionary':
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
type: 'getTranslatedWords',
action: 'storeSelection'
}, (response) => {
if (response) {
contextMenu.saveTranslationToDictionary(info.selectionText, response.translatedWords);
}
});
});
break;
case 'whitelistWebsite':
contextMenu.whitelistURL(tabURL);
setContextMenus(true);
setWhitelist(false);
break;
case 'visualHints':
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
type: 'getTranslatedWords',
action: 'storeSelection'
}, (response) => {
if (response) {
contextMenu.showVisualHints(info.selectionText, response.translatedWords);
}
});
});
break;
default:
console.error('Wrong context menu id');
}
Expand Down
Loading

0 comments on commit a2afcc4

Please sign in to comment.