Skip to content

Commit aa182a2

Browse files
committed
Add basic features
1 parent cf1f801 commit aa182a2

10 files changed

+304
-19
lines changed

.browserslistrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
> 1%
21
last 2 versions

package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint-plugin-promise": "^4.2.1",
2727
"eslint-plugin-standard": "^4.0.0",
2828
"eslint-plugin-vue": "^6.1.2",
29+
"lodash": "^4.17.15",
2930
"vue-cli-plugin-browser-extension": "~0.24.0",
3031
"vue-template-compiler": "^2.6.11"
3132
}

src/global.css

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
html {
2+
background: #242424;
3+
color: #b4b4b4;
4+
box-sizing: border-box;
5+
}
6+
7+
*,
8+
*::before,
9+
*::after {
10+
box-sizing: inherit;
11+
margin: 0;
12+
padding: 0;
13+
}
14+
15+
a {
16+
color: inherit;
17+
}
18+
19+
ol,
20+
ul {
21+
list-style: none;
22+
}

src/manifest.json

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"homepage_url": "http://localhost:8080/",
55
"description": "A Vue Browser Extension",
66
"default_locale": "en",
7-
"permissions": [],
7+
"permissions": [
8+
"<all_urls>",
9+
"bookmarks",
10+
"tabs"
11+
],
812
"icons": {
913
"16": "icons/16.png",
1014
"48": "icons/48.png",
@@ -26,6 +30,16 @@
2630
},
2731
"options_ui": {
2832
"page": "options.html",
29-
"browser_style": true
33+
"chrome_style": true
34+
},
35+
"commands": {
36+
"_execute_browser_action": {
37+
"suggested_key": {
38+
"windows": "Ctrl+E",
39+
"mac": "Command+E",
40+
"chromeos": "Ctrl+E",
41+
"linux": "Ctrl+E"
42+
}
43+
}
3044
}
3145
}

src/mixins/shortcuts.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { find, without } from 'lodash'
2+
3+
const KEYMAP = {
4+
enter: 13,
5+
esc: 27,
6+
space: 32,
7+
up: 38,
8+
down: 40,
9+
}
10+
11+
const shortcuts = {
12+
singleKey: [
13+
{ name: `enter`, key: KEYMAP.enter },
14+
{ name: `esc`, key: KEYMAP.esc },
15+
{ name: `space`, key: KEYMAP.space },
16+
{ name: `up`, key: KEYMAP.up },
17+
{ name: `down`, key: KEYMAP.down },
18+
],
19+
}
20+
21+
let instances = []
22+
23+
const emitShortcut = (name, event) => {
24+
instances.forEach(instance => {
25+
const { shortcuts } = instance.$options
26+
27+
if (shortcuts && typeof shortcuts[name] === `function`) {
28+
shortcuts[name].call(instance, event)
29+
}
30+
})
31+
}
32+
33+
const handleKeydownEvent = event => {
34+
const findAndEmit = (shortcutsCategory, event) => {
35+
const shortcut = find(shortcutsCategory, { key: event.which })
36+
37+
if (shortcut) {
38+
emitShortcut(shortcut.name, event)
39+
}
40+
}
41+
42+
if (event.metaKey && !event.altKey) {
43+
findAndEmit(shortcuts.withMeta, event)
44+
} else if (!event.altKey) {
45+
findAndEmit(shortcuts.singleKey, event)
46+
}
47+
}
48+
49+
document.addEventListener(`keydown`, handleKeydownEvent)
50+
51+
export default {
52+
created () {
53+
instances.push(this)
54+
},
55+
destroyed () {
56+
instances = without(instances, this)
57+
},
58+
}

src/popup/App.vue

-3
This file was deleted.

0 commit comments

Comments
 (0)