Skip to content

Commit

Permalink
Fix keyboard shortcut related issue #17
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Dec 11, 2017
1 parent 83dfcb6 commit eb61bd5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Polyglot.safariextension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>CFBundleVersion</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>Chrome</key>
<dict>
<key>Context Menu Items</key>
Expand Down
2 changes: 2 additions & 0 deletions Polyglot.safariextension/Settings.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<plist version="1.0">
<array>
<dict>
<key>DefaultValue</key>
<string>en</string>
<key>Key</key>
<string>targetLanguage</string>
<key>Title</key>
Expand Down
10 changes: 9 additions & 1 deletion Polyglot.safariextension/global.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const { translate } = require('./api');

// Get settings
const settingsKeys = [
'keyValue',
'useCtrlKey',
'useMetaKey',
'useShiftKey',
'useAltKey',
'targetLanguage',
];
let settings = {};
Object.keys(safari.extension.settings).forEach(key => {
settingsKeys.forEach(key => {
settings[key] = safari.extension.settings[key];
});

Expand Down
8 changes: 4 additions & 4 deletions Polyglot.safariextension/injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function handleKeypress(e) {
return;
}

const applyMeta = settings.useMetaKey ? e.metaKey : true;
const applyShift = settings.useShiftKey ? e.shiftKey : true;
const applyCtrl = settings.useCtrlKey ? e.ctrlKey : true;
const applyAlt = settings.useAltKey ? e.altKey : true;
const applyMeta = settings.useMetaKey === 'true' ? e.metaKey : true;
const applyShift = settings.useShiftKey === 'true' ? e.shiftKey : true;
const applyCtrl = settings.useCtrlKey === 'true' ? e.ctrlKey : true;
const applyAlt = settings.useAltKey === 'true' ? e.altKey : true;
const applyKey = settings.keyValue.charCodeAt(0) === e.keyCode;
if (applyMeta && applyShift && applyCtrl && applyAlt && applyKey) {
e.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions docs/manifest.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<array>
<dict>
<key>CFBundleIdentifier</key>
<string>co.randompaper.safari.polyglot</string>
<string>io.uechi.safari.polyglot</string>
<key>Developer Identifier</key>
<string>58XDWHK3JX</string>
<key>CFBundleVersion</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>URL</key>
<string>https://github.com/uetchy/Polyglot/releases/download/v2.1.0/Polyglot.safariextz</string>
<string>https://github.com/uetchy/Polyglot/releases/download/v2.2.0/Polyglot.safariextz</string>
<key>Update From Gallery</key>
<false/>
</dict>
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"scripts": {
"start": "webpack -w",
"build": "webpack",
"format":
"prettier --write --no-semi --single-quote '{!(node_modules)/**/!(*.entry).{js,jsx},*.js}'"
"format": "prettier --write --no-semi --single-quote '{!(node_modules)/**/!(*.entry).{js,jsx},*.js}'"
},
"dependencies": {
"whatwg-fetch": "^2.0.1"
Expand All @@ -19,7 +18,12 @@
"webpack": "^3.10.0"
},
"babel": {
"presets": ["es2015", "stage-3"],
"plugins": ["transform-runtime"]
"presets": [
"es2015",
"stage-3"
],
"plugins": [
"transform-runtime"
]
}
}

0 comments on commit eb61bd5

Please sign in to comment.