aboutsummaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/content')
-rw-r--r--src/content/actions/find.js49
-rw-r--r--src/content/actions/operation.js2
-rw-r--r--src/content/actions/setting.js7
-rw-r--r--src/content/components/common/index.js13
-rw-r--r--src/content/reducers/addon.js15
-rw-r--r--src/content/reducers/find.js5
-rw-r--r--src/content/reducers/follow-controller.js20
-rw-r--r--src/content/reducers/index.js5
-rw-r--r--src/content/reducers/input.js10
-rw-r--r--src/content/reducers/setting.js2
10 files changed, 63 insertions, 65 deletions
diff --git a/src/content/actions/find.js b/src/content/actions/find.js
index c7345cc..b3d7e30 100644
--- a/src/content/actions/find.js
+++ b/src/content/actions/find.js
@@ -22,6 +22,12 @@ const postPatternFound = (pattern) => {
);
};
+const postNoPrevious = () => {
+ return consoleFrames.postError(
+ window.document,
+ 'No previous search keywords');
+};
+
const find = (string, backwards) => {
let caseSensitive = false;
let wrapScan = true;
@@ -29,44 +35,45 @@ const find = (string, backwards) => {
// NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work
// because of same origin policy
+ let found = window.find(string, caseSensitive, backwards, wrapScan);
+ if (found) {
+ return found;
+ }
+ window.getSelection().removeAllRanges();
return window.find(string, caseSensitive, backwards, wrapScan);
};
-const findNext = (currentKeyword, reset, backwards) => {
+const findNext = async(currentKeyword, reset, backwards) => {
if (reset) {
window.getSelection().removeAllRanges();
}
- let promise = Promise.resolve(currentKeyword);
+ let keyword = currentKeyword;
if (currentKeyword) {
browser.runtime.sendMessage({
type: messages.FIND_SET_KEYWORD,
keyword: currentKeyword,
});
} else {
- promise = browser.runtime.sendMessage({
+ keyword = await browser.runtime.sendMessage({
type: messages.FIND_GET_KEYWORD,
});
}
+ if (!keyword) {
+ return postNoPrevious();
+ }
+ let found = find(keyword, backwards);
+ if (found) {
+ postPatternFound(keyword);
+ } else {
+ postPatternNotFound(keyword);
+ }
- return promise.then((keyword) => {
- let found = find(keyword, backwards);
- if (!found) {
- window.getSelection().removeAllRanges();
- found = find(keyword, backwards);
- }
- if (found) {
- postPatternFound(keyword);
- } else {
- postPatternNotFound(keyword);
- }
-
- return {
- type: actions.FIND_SET_KEYWORD,
- keyword,
- found,
- };
- });
+ return {
+ type: actions.FIND_SET_KEYWORD,
+ keyword,
+ found,
+ };
};
const next = (currentKeyword, reset) => {
diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js
index 9171766..40ac52d 100644
--- a/src/content/actions/operation.js
+++ b/src/content/actions/operation.js
@@ -8,7 +8,7 @@ import * as consoleFrames from 'content/console-frames';
import * as addonActions from './addon';
import * as properties from 'shared/settings/properties';
-// eslint-disable-next-line complexity
+// eslint-disable-next-line complexity, max-lines-per-function
const exec = (operation, repeat, settings) => {
let smoothscroll = settings.properties.smoothscroll ||
properties.defaults.smoothscroll;
diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js
index 4c1e385..e34b6e0 100644
--- a/src/content/actions/setting.js
+++ b/src/content/actions/setting.js
@@ -10,7 +10,7 @@ const reservedKeymaps = {
const set = (value) => {
let entries = [];
if (value.keymaps) {
- let keymaps = Object.assign({}, value.keymaps, reservedKeymaps);
+ let keymaps = { ...value.keymaps, ...reservedKeymaps };
entries = Object.entries(keymaps).map((entry) => {
return [
keyUtils.fromMapKeys(entry[0]),
@@ -21,9 +21,8 @@ const set = (value) => {
return {
type: actions.SETTING_SET,
- value: Object.assign({}, value, {
- keymaps: entries,
- })
+ value: { ...value,
+ keymaps: entries, }
};
};
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index 9b7b083..6437011 100644
--- a/src/content/components/common/index.js
+++ b/src/content/components/common/index.js
@@ -44,15 +44,16 @@ export default class Common {
}
}
- reloadSettings() {
- browser.runtime.sendMessage({
- type: messages.SETTINGS_QUERY,
- }).then((settings) => {
+ async reloadSettings() {
+ try {
+ let settings = await browser.runtime.sendMessage({
+ type: messages.SETTINGS_QUERY,
+ });
this.store.dispatch(settingActions.set(settings));
- }).catch((e) => {
+ } catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);
setTimeout(() => this.reloadSettings(), 500);
- });
+ }
}
}
diff --git a/src/content/reducers/addon.js b/src/content/reducers/addon.js
index 8cc5ef1..b881ca0 100644
--- a/src/content/reducers/addon.js
+++ b/src/content/reducers/addon.js
@@ -7,17 +7,14 @@ const defaultState = {
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.ADDON_ENABLE:
- return Object.assign({}, state, {
- enabled: true,
- });
+ return { ...state,
+ enabled: true, };
case actions.ADDON_DISABLE:
- return Object.assign({}, state, {
- enabled: false,
- });
+ return { ...state,
+ enabled: false, };
case actions.ADDON_TOGGLE_ENABLED:
- return Object.assign({}, state, {
- enabled: !state.enabled,
- });
+ return { ...state,
+ enabled: !state.enabled, };
default:
return state;
}
diff --git a/src/content/reducers/find.js b/src/content/reducers/find.js
index 8d63ee5..4560e2c 100644
--- a/src/content/reducers/find.js
+++ b/src/content/reducers/find.js
@@ -8,10 +8,9 @@ const defaultState = {
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.FIND_SET_KEYWORD:
- return Object.assign({}, state, {
+ return { ...state,
keyword: action.keyword,
- found: action.found,
- });
+ found: action.found, };
default:
return state;
}
diff --git a/src/content/reducers/follow-controller.js b/src/content/reducers/follow-controller.js
index 78fd848..5869c47 100644
--- a/src/content/reducers/follow-controller.js
+++ b/src/content/reducers/follow-controller.js
@@ -10,24 +10,20 @@ const defaultState = {
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.FOLLOW_CONTROLLER_ENABLE:
- return Object.assign({}, state, {
+ return { ...state,
enabled: true,
newTab: action.newTab,
background: action.background,
- keys: '',
- });
+ keys: '', };
case actions.FOLLOW_CONTROLLER_DISABLE:
- return Object.assign({}, state, {
- enabled: false,
- });
+ return { ...state,
+ enabled: false, };
case actions.FOLLOW_CONTROLLER_KEY_PRESS:
- return Object.assign({}, state, {
- keys: state.keys + action.key,
- });
+ return { ...state,
+ keys: state.keys + action.key, };
case actions.FOLLOW_CONTROLLER_BACKSPACE:
- return Object.assign({}, state, {
- keys: state.keys.slice(0, -1),
- });
+ return { ...state,
+ keys: state.keys.slice(0, -1), };
default:
return state;
}
diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js
index 2487d85..c3a474e 100644
--- a/src/content/reducers/index.js
+++ b/src/content/reducers/index.js
@@ -14,11 +14,12 @@ const defaultState = {
};
export default function reducer(state = defaultState, action = {}) {
- return Object.assign({}, state, {
+ return {
+ ...state,
addon: addonReducer(state.addon, action),
find: findReducer(state.find, action),
setting: settingReducer(state.setting, action),
input: inputReducer(state.input, action),
followController: followControllerReducer(state.followController, action),
- });
+ };
}
diff --git a/src/content/reducers/input.js b/src/content/reducers/input.js
index 134aa95..23e7dd2 100644
--- a/src/content/reducers/input.js
+++ b/src/content/reducers/input.js
@@ -7,13 +7,11 @@ const defaultState = {
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.INPUT_KEY_PRESS:
- return Object.assign({}, state, {
- keys: state.keys.concat([action.key]),
- });
+ return { ...state,
+ keys: state.keys.concat([action.key]), };
case actions.INPUT_CLEAR_KEYS:
- return Object.assign({}, state, {
- keys: [],
- });
+ return { ...state,
+ keys: [], };
default:
return state;
}
diff --git a/src/content/reducers/setting.js b/src/content/reducers/setting.js
index a23027f..a49db6d 100644
--- a/src/content/reducers/setting.js
+++ b/src/content/reducers/setting.js
@@ -8,7 +8,7 @@ const defaultState = {
export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.SETTING_SET:
- return Object.assign({}, action.value);
+ return { ...action.value };
default:
return state;
}