error title

jh-changes
Shin'ya Ueoka 7 years ago
parent d51b674467
commit d5007a747c
  1. 36
      src/console/console-frame.js
  2. 2
      src/console/console.html
  3. 21
      src/console/console.js
  4. 13
      src/content/index.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';
}
}

@ -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>

@ -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;
});
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;
}
});

@ -5,7 +5,7 @@ import * as messages from '../shared/messages';
import ConsoleFrame from '../console/console-frame';
import Follow from './follow';
let cmd = null;
let vvConsole = new ConsoleFrame(window);
const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) {
@ -14,14 +14,14 @@ const invokeEvent = (action) => {
switch (action[0]) {
case actions.CMD_OPEN:
cmd = new ConsoleFrame(window);
vvConsole.showCommand('');
break;
case actions.CMD_TABS_OPEN:
if (action[1] || false) {
// alter url
cmd = new ConsoleFrame(window, 'open ' + window.location.href);
vvConsole.showCommand('open ' + window.location.href);
} else {
cmd = new ConsoleFrame(window, 'open ');
vvConsole.showCommand('open ');
}
break;
case actions.SCROLL_LINES:
@ -75,10 +75,7 @@ window.addEventListener("keypress", (e) => {
messages.receive(window, (message) => {
switch (message.type) {
case 'vimvixen.commandline.blur':
if (cmd) {
cmd.remove();
cmd = null;
}
vvConsole.hide();
break;
case 'vimvixen.commandline.enter':
browser.runtime.sendMessage({