MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / promptRegister

Function promptRegister

external_resource/prompt/page/prompt.js:13–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11document.addEventListener("DOMContentLoaded", promptRegister);
12
13function promptRegister() {
14 //get custom session id
15 promptId = document.location.hash.replace("#", "");
16
17 //get options from back
18 try {
19 promptOptions = JSON.parse(
20 ipcRenderer.sendSync("prompt-get-options:" + promptId)
21 );
22 } catch (error) {
23 return promptError(error);
24 }
25
26 //set label
27 if (promptOptions.useHtmlLabel) {
28 $("#label").innerHTML = promptOptions.label;
29 } else {
30 $("#label").textContent = promptOptions.label;
31 }
32
33 //set button label
34 if (promptOptions.buttonLabels && promptOptions.buttonLabels.ok) {
35 $("#ok").textContent = promptOptions.buttonLabels.ok;
36 }
37
38 if (promptOptions.buttonLabels && promptOptions.buttonLabels.cancel) {
39 $("#cancel").textContent = promptOptions.buttonLabels.cancel;
40 }
41
42 //inject custom stylesheet from options
43 if (promptOptions.customStylesheet) {
44 try {
45 const customStyleContent = fs.readFileSync(
46 promptOptions.customStylesheet
47 );
48 if (customStyleContent) {
49 const customStyle = document.createElement("style");
50 customStyle.setAttribute("rel", "stylesheet");
51 customStyle.append(document.createTextNode(customStyleContent));
52 document.head.append(customStyle);
53 }
54 } catch (error) {
55 return promptError(error);
56 }
57 }
58
59 //add button listeners
60 $("#form").addEventListener("submit", promptSubmit);
61 $("#cancel").addEventListener("click", promptCancel);
62
63 //create input/select/counter/keybind
64 const dataContainerElement = $("#data-container");
65 const buttonsContainer = $("#buttons");
66
67 switch (promptOptions.type) {
68 case "counter":
69 dataElement = promptCreateCounter(dataContainerElement);
70 break;

Callers

nothing calls this directly

Calls 9

promptErrorFunction · 0.85
$Function · 0.85
promptCreateCounterFunction · 0.85
promptCreateInputFunction · 0.85
promptCreateSelectFunction · 0.85
promptCreateMultiInputFunction · 0.85
appendMethod · 0.80
callMethod · 0.80
focusMethod · 0.45

Tested by

no test coverage detected