Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,26 @@ function saveWord (content) {
definitions
});
})
}
}

browser.contextMenus.create({
id: "dictionary-anywhere-selection",
title: "Look up '%s' in Dictionary",
contexts: ["selection"]
});

browser.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "dictionary-anywhere-selection") {
const code = `showMeaning({});`;

browser.tabs.executeScript({
code: "typeof showMeaning === 'function';",
}).then(() => {
return browser.tabs.executeScript(tab.id, {
code,
});
}).catch((error) => {
console.error("Failed to translate text: " + error);
});
}
});
2 changes: 2 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

"permissions": [
"storage",
"contextMenus",
"activeTab",
"https://www.google.com/"
]
}
1 change: 1 addition & 0 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<option value="ctrl" id="popup-dblclick-key-ctrl">Ctrl</option>
<option value="alt">Alt</option>
<option value="shift">Shift</option>
<option value="onlyRightClick">Only right click</option>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this "onlyRightClick" used? seems missing usage of it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of pressing down Alt or Control now you can also ‘right click‘ and select ‘ Look up '%s' in Dictionary’ from the context menu. See the background.js and manifest.json files

</select>
</div>
</div>
Expand Down