~glacambre/firenvim

ref: 076c1a4f04db2173afb395d0af8c63a5bbcab6a8 firenvim/src/compose.ts -rw-r--r-- 2.7 KiB
076c1a4f — Brian Ryall fixes installing fire nvim on brave 11 months ago
                                                                                
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { FirenvimElement } from "./FirenvimElement";
import { executeInPage } from "./utils/utils";

const computedStyles : {[k:string]: CSSStyleDeclaration} = {
    documentElement: window.getComputedStyle(document.documentElement),
    body: window.getComputedStyle(document.body),
};
const overridenStyles : {[k: string]: string} = {
    "height": "100%",
    "width": "100%",
    "marginBottom": "0px",
    "marginLeft": "0px",
    "marginRight": "0px",
    "marginTop": "0px",
    "paddingBottom": "0px",
    "paddingLeft": "0px",
    "paddingRight": "0px",
    "paddingTop": "0px",
};
function restoreComputedStyles (_: any) {
    for (const element of Object.keys(computedStyles)) {
        const e = (document as any)[element];
        for (const style of Object.keys(overridenStyles)) {
            e.style[style] = (computedStyles as any)[element][style];
        }
    }
}
function overrideComputedStyles () {
    for (const element of Object.keys(computedStyles)) {
        const e = (document as any)[element];
        for (const style of Object.keys(overridenStyles)) {
            e.style[style] = overridenStyles[style];
        }
    }
}
overrideComputedStyles();

const firenvimElement = new FirenvimElement(document.body, () => Promise.resolve(), restoreComputedStyles);

firenvimElement.attachToPage(
    new Promise((resolve, reject) => {
        setTimeout(reject, 10000);
        browser.runtime.onMessage.addListener((request: { funcName: string[], args: any[] }) => {
            const args = request.args;
            switch (request.funcName[0]) {
                case "evalInPage": return executeInPage(args[1]);
                case "focusInput": throw new Error("focusInput not implemented in Thunderbird");
                case "focusPage": throw new Error("focusPage not implemented in Thunderbird");
                case "getEditorInfo": return firenvimElement.getBufferInfo();
                case "getElementContent": return firenvimElement.getPageElementContent();
                case "hideEditor": throw new Error("hideEditor not implemented in Thunderbird");
                case "killEditor": return firenvimElement.detachFromPage();
                case "pressKeys": throw new Error("pressKeys not implemented in Thunderbird");
                case "registerNewFrameId": return (resolve(request.args[0]));
                case "resizeEditor": throw new Error("resizeEditor not implemented in Thunderbird");
                case "setElementContent": return firenvimElement.setPageElementContent(args[1]);
                case "setElementCursor": return firenvimElement.setPageElementCursor(args[1], args[2]);
                default: throw new Error("Unhandeld request: " + JSON.stringify(request));
            }
        });
    })
);