Grammalecte  Check-in [2bedf50a10]

Overview
Comment:[fx] Web API: warn the webpage when the API script is loaded
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 2bedf50a1007a6f810af0e0b726d4d1a4aa51115ff4852205e364c12de3f251e
User & Date: olr on 2020-03-21 15:13:47
Other Links: manifest | tags
Context
2020-03-21
15:58
[fx] selection analysis: don’t send directly text from background to the GC check-in: 76e08d6ee8 user: olr tags: trunk, fx
15:13
[fx] Web API: warn the webpage when the API script is loaded check-in: 2bedf50a10 user: olr tags: trunk, fx
14:41
[doc] Web API update: add JSON.parse(event.detail) check-in: ce33035715 user: olr tags: trunk, doc
Changes

Modified gc_lang/fr/webext/content_scripts/api.js from [8cd25765a3] to [6ff89127c7].

83
84
85
86
87
88
89






83
84
85
86
87
88
89
90
91
92
93
94
95







+
+
+
+
+
+
            let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sRequestId: sRequestId} });
            document.dispatchEvent(xEvent);
        } else {
            console.log("[Grammalecte API] Error: one or several parameters aren’t string.");
        }
    }
}

/*
    Tell to the webpage that the Grammalecte API is ready.
*/
document.dispatchEvent(new Event('GrammalecteLoaded'));

Modified gc_lang/fr/webext/content_scripts/init.js from [316d25a5ff] to [ae034ec96f].

516
517
518
519
520
521
522
523

524
525
526
527
528
529
530

531
532
533
534
535
536
537
516
517
518
519
520
521
522

523
524




525
526
527
528
529
530
531
532
533
534







-
+

-
-
-
-


+







oGrammalecteBackgroundPort.listen()
oGrammalecteBackgroundPort.listen2()



/*
    Callable API for the webpage.
    The API script must be injected this way to be callable by the page

*/
let xScriptGrammalecteAPI = document.createElement("script");
xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js");
document.documentElement.appendChild(xScriptGrammalecteAPI);

document.addEventListener("GrammalecteCall", function (xEvent) {
    // GrammalecteCall events are dispatched by functions in the API script
    // The script is loaded below.
    try {
        let oCommand = xEvent.detail;
        switch (oCommand.sCommand) {
            case "openPanelForNode":
                if (oCommand.xNode) {
                    oGrammalecte.startGCPanel(oCommand.xNode);
                }
563
564
565
566
567
568
569





570
571
572
573
574
575
576
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578







+
+
+
+
+







                console.log("[Grammalecte] Event: Unknown command", oCommand.sCommand);
        }
    }
    catch (e) {
        showError(e);
    }
});

// The API script must be injected this way to be callable by the page
let xScriptGrammalecteAPI = document.createElement("script");
xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js");
document.documentElement.appendChild(xScriptGrammalecteAPI);


/*
    Note:
    Initialization starts when the background is connected.
    See: oGrammalecteBackgroundPort.listen() -> case "init"
*/