aboutsummaryrefslogtreecommitdiff
path: root/src/content/console-frames.ts
blob: bd6b835995265e28d7131a9c866c705e61b06bdd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as messages from '../shared/messages';

const initialize = (doc: Document): HTMLIFrameElement => {
  let iframe = doc.createElement('iframe');
  iframe.src = browser.runtime.getURL('build/console.html');
  iframe.id = 'vimvixen-console-frame';
  iframe.className = 'vimvixen-console-frame';
  doc.body.append(iframe);

  return iframe;
};

const blur = (doc: Document) => {
  let ele = doc.getElementById('vimvixen-console-frame') as HTMLIFrameElement;
  ele.blur();
};

const postError = (text: string): Promise<any> => {
  return browser.runtime.sendMessage({
    type: messages.CONSOLE_FRAME_MESSAGE,
    message: {
      type: messages.CONSOLE_SHOW_ERROR,
      text,
    },
  });
};

const postInfo = (text: string): Promise<any> => {
  return browser.runtime.sendMessage({
    type: messages.CONSOLE_FRAME_MESSAGE,
    message: {
      type: messages.CONSOLE_SHOW_INFO,
      text,
    },
  });
};

export { initialize, blur, postError, postInfo };