-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (82 loc) · 3.02 KB
/
index.js
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
function stringGen() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 12; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function spawnwindow(name, URL, icon, height, width) {
//configure elements
var section = document.getElementById("section");
var footer = document.getElementById("footer1");
var window = document.createElement("div");
var header = document.createElement("div");
var content = document.createElement("div");
var webview = document.createElement("iframe");
var minimized = document.createElement("button");
var close = document.createElement("button");
var minimize = document.createElement("button");
var appID = stringGen()
//create window
window.classList.add('window');
window.id = name + appID;
window.style.display = "block";
window.onclick = function () {
focusWindow(window)
}
//create header
header.classList.add('header');
header.style.width = width;
header.innerHTML = "<button class='headertext'>" + name + "</button>";
//create close button
close.innerHTML = '<i class="fa-solid fa-xmark"></i>';
close.classList.add('closebutton');
close.onclick = function () {
window.remove();
minimized.remove();
}
//create minimize button
minimize.innerHTML = '<i class="fa-solid fa-window-minimize"></i>';
minimize.classList.add('minimize');
minimize.onclick = function () {
window.style.display = "none"
minimized.className = "menubuttonminimized"
}
//create content div
content.classList.add('content');
//create webview
webview.style.height = height;
webview.style.width = width;
webview.src = URL;
webview.setAttribute("webpreferences", "contextIsolation=false");
webview.setAttribute("nodeintegration", "");
// webview.addEventListener('did-finish-load', function () {
// webview.openDevTools()
// });
//create minimized icon
minimized.innerHTML = "<i class='" + icon + "''></i>";
minimized.className = "menubuttonminimized menubuttonminimizing"
minimized.onclick = function () {
window.style.display = "block"
minimized.className = "menubuttonminimized menubuttonminimizing"
}
//append the elements
section.prepend(window);
window.appendChild(header);
header.appendChild(close);
header.appendChild(minimize)
window.appendChild(content);
content.appendChild(webview);
footer.appendChild(minimized);
//make the window draggable
$(".window").draggable({
handle: ".header",
containment: "#body",
opacity: 0.75
});
}
function focusWindow(windowElem) {
const windows = document.querySelectorAll('.window');
windows.forEach((elem) => elem.classList.remove('focused'));
windowElem.classList.add('focused');
}