This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebjssdk.js
More file actions
107 lines (83 loc) · 4.34 KB
/
Copy pathwebjssdk.js
File metadata and controls
107 lines (83 loc) · 4.34 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
__ __ _ _ ___ ___ ___ _ __
\ \ / / ___ | |__ _ | |/ __| / __|| \ | |/ /
\ \/\/ / / -_)| _ \| || |\__ \ \__ \| |) || <
\_/\_/ \___||____/ \__/ |___/ |___/|___/ |_|\_\
WebJS SDK 1.0.1 by C1200
*/
// Better Dialogs
function betterdialogs_prompt(message, _default, callback) {
var modal = document.getElementsByClassName("webjsmodal")[0];
var modalcontent = document.createElement("div");
modalcontent.setAttribute("class", "webjsmodalcontent");
var modalclose = document.createElement("span");
modalclose.setAttribute("class", "webjsmodalclose");
modalclose.innerHTML = "×";
modalclose.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(null); }
modalcontent.appendChild(modalclose);
var msg = document.createElement("p");
msg.innerHTML = message;
modalcontent.appendChild(msg);
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("value", _default);
input.onkeypress = (ev) => { if (ev.key == "Enter") { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(input.value); } }
modalcontent.appendChild(input);
var okbtn = document.createElement("button");
okbtn.setAttribute("class", "webjsmodalbutton");
okbtn.innerHTML = "OK";
okbtn.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(input.value); }
modalcontent.appendChild(okbtn);
modal.appendChild(modalcontent);
modal.setAttribute("style", "display:block");
}
function betterdialogs_alert(message) {
var modal = document.getElementsByClassName("webjsmodal")[0];
var modalcontent = document.createElement("div");
modalcontent.setAttribute("class", "webjsmodalcontent");
var modalclose = document.createElement("span");
modalclose.setAttribute("class", "webjsmodalclose");
modalclose.innerHTML = "×";
modalclose.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); }
modalcontent.appendChild(modalclose);
var msg = document.createElement("p");
msg.innerHTML = message;
modalcontent.appendChild(msg);
modal.appendChild(modalcontent);
modal.setAttribute("style", "display:block");
}
function betterdialogs_confirm(message, callback) {
var modal = document.getElementsByClassName("webjsmodal")[0];
var modalcontent = document.createElement("div");
modalcontent.setAttribute("class", "webjsmodalcontent");
var modalclose = document.createElement("span");
modalclose.setAttribute("class", "webjsmodalclose");
modalclose.innerHTML = "×";
modalclose.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(false); }
modalcontent.appendChild(modalclose);
var msg = document.createElement("p");
msg.innerHTML = message;
modalcontent.appendChild(msg);
var okbtn = document.createElement("button");
okbtn.setAttribute("class", "webjsmodalbutton");
okbtn.innerHTML = "OK";
okbtn.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(true); }
modalcontent.appendChild(okbtn);
var cancelbtn = document.createElement("button");
cancelbtn.setAttribute("class", "webjsmodalbutton");
cancelbtn.innerHTML = "Cancel";
cancelbtn.onclick = () => { modal.childNodes.forEach((child) => { modal.removeChild(child); }); modal.setAttribute("style", "display:none"); callback(false); }
modalcontent.appendChild(cancelbtn);
modal.appendChild(modalcontent);
modal.setAttribute("style", "display:block");
}
// WebJS SDK Setup
window.onload = function() {
var modaldiv = document.createElement("div");
modaldiv.setAttribute("class", "webjsmodal");
document.body.appendChild(modaldiv);
var styles = document.createElement("link");
styles.setAttribute("rel", "stylesheet");
styles.setAttribute("href", "https://cdn.jsdelivr.net/gh/C1200/WebJS-SDK@1.0.1/src/styles.css");
document.head.appendChild(styles);
}