Use webextension message to console
This commit is contained in:
parent
8220336130
commit
63b93ce1ca
7 changed files with 47 additions and 41 deletions
|
@ -9,25 +9,6 @@ import messages from 'shared/messages';
|
|||
import actions from 'content/actions';
|
||||
import * as consoleFrames from '../console-frames';
|
||||
|
||||
const postPatternNotFound = (pattern) => {
|
||||
return consoleFrames.postError(
|
||||
window.document,
|
||||
'Pattern not found: ' + pattern);
|
||||
};
|
||||
|
||||
const postPatternFound = (pattern) => {
|
||||
return consoleFrames.postInfo(
|
||||
window.document,
|
||||
'Pattern found: ' + pattern,
|
||||
);
|
||||
};
|
||||
|
||||
const postNoPrevious = () => {
|
||||
return consoleFrames.postError(
|
||||
window.document,
|
||||
'No previous search keywords');
|
||||
};
|
||||
|
||||
const find = (string, backwards) => {
|
||||
let caseSensitive = false;
|
||||
let wrapScan = true;
|
||||
|
@ -60,13 +41,13 @@ const findNext = async(currentKeyword, reset, backwards) => {
|
|||
});
|
||||
}
|
||||
if (!keyword) {
|
||||
return postNoPrevious();
|
||||
return consoleFrames.postError('No previous search keywords');
|
||||
}
|
||||
let found = find(keyword, backwards);
|
||||
if (found) {
|
||||
postPatternFound(keyword);
|
||||
consoleFrames.postInfo('Pattern found: ' + keyword);
|
||||
} else {
|
||||
postPatternNotFound(keyword);
|
||||
consoleFrames.postError('Pattern not found: ' + keyword);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -85,7 +85,7 @@ const exec = (operation, repeat, settings, addonEnabled) => {
|
|||
break;
|
||||
case operations.URLS_YANK:
|
||||
urls.yank(window);
|
||||
consoleFrames.postInfo(window.document, 'Current url yanked');
|
||||
consoleFrames.postInfo('Current url yanked');
|
||||
break;
|
||||
case operations.URLS_PASTE:
|
||||
urls.paste(
|
||||
|
|
|
@ -33,7 +33,7 @@ export default class MarkComponent {
|
|||
}
|
||||
|
||||
if (key.ctrlKey || key.metaKey || key.altKey) {
|
||||
consoleFrames.postError(window.document, 'Unknown mark');
|
||||
consoleFrames.postError('Unknown mark');
|
||||
} else if (globalKey(key.key) && markStage.setMode) {
|
||||
this.doSetGlobal(key);
|
||||
} else if (globalKey(key.key) && markStage.jumpMode) {
|
||||
|
@ -55,7 +55,7 @@ export default class MarkComponent {
|
|||
|
||||
doJump(marks, key, smoothscroll) {
|
||||
if (!marks[key.key]) {
|
||||
consoleFrames.postError(window.document, 'Mark is not set');
|
||||
consoleFrames.postError('Mark is not set');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,22 +16,23 @@ const blur = (doc) => {
|
|||
iframe.blur();
|
||||
};
|
||||
|
||||
const postMessage = (doc, message) => {
|
||||
let iframe = doc.getElementById('vimvixen-console-frame');
|
||||
iframe.contentWindow.postMessage(JSON.stringify(message), '*');
|
||||
};
|
||||
|
||||
const postError = (doc, message) => {
|
||||
return postMessage(doc, {
|
||||
type: messages.CONSOLE_SHOW_ERROR,
|
||||
text: message,
|
||||
const postError = (text) => {
|
||||
browser.runtime.sendMessage({
|
||||
type: messages.CONSOLE_FRAME_MESSAGE,
|
||||
message: {
|
||||
type: messages.CONSOLE_SHOW_ERROR,
|
||||
text,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const postInfo = (doc, message) => {
|
||||
return postMessage(doc, {
|
||||
type: messages.CONSOLE_SHOW_INFO,
|
||||
text: message,
|
||||
const postInfo = (text) => {
|
||||
browser.runtime.sendMessage({
|
||||
type: messages.CONSOLE_FRAME_MESSAGE,
|
||||
message: {
|
||||
type: messages.CONSOLE_SHOW_INFO,
|
||||
text,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue