Grammalecte  Check-in [cf71e46511]

Overview
Comment:[fx] web API: generate id when node has no id
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: cf71e46511542118c792ccecd830e6e292e589cbd603dc28f7ad1086fa8518b2
User & Date: olr on 2020-04-07 16:25:49
Other Links: manifest | tags
Context
2020-04-07
22:21
[fr] faux positif et ajustements check-in: 26c9bbaed1 user: olr tags: fr, trunk
16:25
[fx] web API: generate id when node has no id check-in: cf71e46511 user: olr tags: fx, trunk
16:13
[fr] ajustements check-in: 38cda6c0bb user: olr tags: fr, trunk
Changes

Modified gc_lang/fr/webext/content_scripts/api.js from [4233cac483] to [2457ed4f51].

     4      4   
     5      5   
     6      6   const oGrammalecteAPI = {
     7      7       // functions callable from within pages
     8      8       // to be sent to the content-cript via an event “GrammalecteCall”
     9      9   
    10     10       sVersion: "1.0",
           11  +
           12  +    generateNodeId: function (xNode) {
           13  +        xNode.id = "grammalecte_generated_id_" + Date.now().toString(36) + "_" + (Math.floor(Math.random() * (1000000))).toString(36);
           14  +        console.log("[Grammalecte API] generated id", xNode.id);
           15  +        return xNode.id;
           16  +    },
    11     17   
    12     18       openPanelForNode: function (vNode) {
    13     19           //  Parameter: a HTML node or the identifier of a HTML node
    14         -        if (vNode instanceof HTMLElement && vNode.id) {
    15         -            let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: vNode.id}) });
           20  +        if (vNode instanceof HTMLElement) {
           21  +            let sNodeId = vNode.id || this.generateNodeId(vNode);
           22  +            let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: sNodeId}) });
    16     23               document.dispatchEvent(xEvent);
    17     24           }
    18     25           else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
    19     26               let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: vNode}) });
    20     27               document.dispatchEvent(xEvent);
    21     28           }
    22     29           else {
................................................................................
    24     31           }
    25     32       },
    26     33   
    27     34       openPanelForText: function (sText, vNode=null) {
    28     35           //  Parameter: text to analyze, and optionaly a node to send results to.
    29     36           if (typeof(sText) === "string") {
    30     37               let sNodeId = "";
    31         -            if (vNode instanceof HTMLElement && vNode.id) {
    32         -                sNodeId = vNode.id;
           38  +            if (vNode instanceof HTMLElement) {
           39  +                sNodeId = vNode.id || this.generateNodeId(vNode);
    33     40               }
    34     41               else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
    35     42                   sNodeId = vNode;
    36     43               }
    37     44               else {
    38     45                   console.log("[Grammalecte API] No node identifier. No event, no result will be sent.")
    39     46               }
................................................................................
    44     51           }
    45     52       },
    46     53   
    47     54       parseNode: function (vNode) {
    48     55           /*  Parameter: a HTML node (with a identifier) or the identifier of a HTML node.
    49     56               The result will be sent as an event “GrammalecteResult” to the node.
    50     57           */
    51         -        if (vNode instanceof HTMLElement  &&  vNode.id) {
    52         -            let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: vNode.id}) });
           58  +        if (vNode instanceof HTMLElement) {
           59  +            let sNodeId = vNode.id || this.generateNodeId(vNode);
           60  +            let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: sNodeId}) });
    53     61               document.dispatchEvent(xEvent);
    54     62           }
    55     63           else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
    56     64               let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: vNode}) });
    57     65               document.dispatchEvent(xEvent);
    58     66           }
    59     67           else {
................................................................................
    60     68               console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier.");
    61     69           }
    62     70       },
    63     71   
    64     72       parseText: function (sText, vNode) {
    65     73           //  Parameter: text to analyze, and a node to send results to.
    66     74           if (typeof(sText) === "string") {
    67         -            if (vNode instanceof HTMLElement  &&  vNode.id) {
    68         -                let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: vNode.id}) });
           75  +            if (vNode instanceof HTMLElement) {
           76  +                let sNodeId = vNode.id || this.generateNodeId(vNode);
           77  +                let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: sNodeId}) });
    69     78                   document.dispatchEvent(xEvent);
    70     79               }
    71     80               else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
    72     81                   let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: vNode}) });
    73     82                   document.dispatchEvent(xEvent);
    74     83               }
    75     84               else {