Skip to content

Commit

Permalink
Merge pull request #32 from mehmetb/31-add-a-keyboard-shortcut-for-di…
Browse files Browse the repository at this point in the history
…mming-only-the-current-tab

Added a new shortcut to dim only the active tab
  • Loading branch information
mehmetb authored Nov 11, 2023
2 parents 9af1bfb + 8d96eae commit 266e939
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ icons/
web-ext-artifacts/
.env
.DS_Store
*.code-workspace
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ A browser extension to dim web pages. [Add it to Firefox](https://addons.mozilla

![Dimmer Demo](demo.gif)

*Note:* Default shortcut is: <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>N</kbd>. You can change it from `about:addons` -> Manage Your Extension -> Manage Extension Shortcuts.
### Shortcuts

- Toggle Dim (All tabs)
Default: <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>N</kbd> (Windows), <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>N</kbd> (Mac)
- Toggle Dim (Active tab only)
Default: <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>B</kbd> (Windows), <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>B</kbd> (Mac)

*Note:* You can change the shortcuts from `about:addons` -> Manage Your Extension -> Manage Extension Shortcuts.

### Settings

Expand Down
14 changes: 13 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,24 @@ async function getActiveTab() {
*/
async function handleCommand(commandName) {
switch (commandName) {
case 'toggle-dim': {
case 'Toggle Dim (All tabs)': {
const activeTab = await getActiveTab();
const state = getState(activeTab.id);
return setState(activeTab.id, 'isDimmed', !state.isDimmed);
}

case 'Toggle Dim (Active tab only)': {
const activeTab = await getActiveTab();
const state = getState(activeTab.id);

if (!localStateTabs.has(activeTab.id)) {
globalStateTabs.delete(activeTab.id);
localStateTabs.set(activeTab.id, { ...globalState });
}

return setState(activeTab.id, 'isDimmed', !state.isDimmed);
}

default: {
return Promise.resolve();
}
Expand Down
7 changes: 6 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@
},

"commands": {
"toggle-dim": {
"Toggle Dim (All tabs)": {
"suggested_key": {
"default": "Ctrl+Alt+N"
}
},
"Toggle Dim (Active tab only)": {
"suggested_key": {
"default": "Ctrl+Alt+B"
}
}
},

Expand Down

0 comments on commit 266e939

Please sign in to comment.