aboutsummaryrefslogtreecommitdiff
path: root/src/console
diff options
context:
space:
mode:
Diffstat (limited to 'src/console')
-rw-r--r--src/console/console-frame.js36
-rw-r--r--src/console/console.html2
-rw-r--r--src/console/console.js23
3 files changed, 46 insertions, 15 deletions
diff --git a/src/console/console-frame.js b/src/console/console-frame.js
index cf72f25..f8aeeeb 100644
--- a/src/console/console-frame.js
+++ b/src/console/console-frame.js
@@ -1,19 +1,43 @@
import './console-frame.scss';
+import * as messages from '../shared/messages';
export default class ConsoleFrame {
constructor(win, initial = '') {
- let url = browser.runtime.getURL('build/console.html') +
- '#' + encodeURIComponent(initial);
-
let element = window.document.createElement('iframe');
- element.src = url;
+ element.src = browser.runtime.getURL('build/console.html');
element.className = 'vimvixen-console-frame';
win.document.body.append(element);
this.element = element;
+
+ this.hide();
+ }
+
+ showCommand(text) {
+ this.showFrame();
+
+ let message = {
+ type: 'vimvixen.console.show.command',
+ text: text
+ };
+ messages.send(this.element.contentWindow, message);
+ }
+
+ showError(text) {
+ this.showFrame();
+
+ let message = {
+ type: 'vimvixen.console.show.error',
+ text: text
+ };
+ messages.send(this.element.contentWindow, message);
+ }
+
+ showFrame() {
+ this.element.style.display = 'block';
}
- remove() {
- this.element.remove();
+ hide() {
+ this.element.style.display = 'none';
}
}
diff --git a/src/console/console.html b/src/console/console.html
index feee5d0..228660b 100644
--- a/src/console/console.html
+++ b/src/console/console.html
@@ -6,7 +6,7 @@
<script src='console.js'></script>
</head>
<body class='vimvixen-console'>
- <p id='vimvixen-console-title'
+ <p id='vimvixen-console-error'
class='vimvixen-console-error'></p>
<div>
<p class='vimvixen-console-title'></p>
diff --git a/src/console/console.js b/src/console/console.js
index 67b9eab..2db9d29 100644
--- a/src/console/console.js
+++ b/src/console/console.js
@@ -50,16 +50,23 @@ const handleKeyup = (e) => {
};
window.addEventListener('load', () => {
- let hash = window.location.hash;
- let initial = '';
- if (hash.length > 0) {
- initial = decodeURIComponent(hash.substring(1));
- }
-
let input = window.document.querySelector('#vimvixen-console-command-input');
input.addEventListener('blur', handleBlur);
input.addEventListener('keydown', handleKeydown);
input.addEventListener('keyup', handleKeyup);
- input.value = initial;
- input.focus();
+});
+
+messages.receive(window, (message) => {
+ switch (message.type) {
+ case 'vimvixen.console.show.command':
+ if (message.text) {
+ let input = window.document.querySelector('#vimvixen-console-command-input');
+ input.value = message.text;
+ input.focus();
+ }
+ break;
+ case 'vimvixen.console.show.error':
+ window.document.querySelector('#vimvixen-console-error').textContent = message.text;
+ break;
+ }
});