-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
154 lines (131 loc) · 5.82 KB
/
Copy pathIndex.html
File metadata and controls
154 lines (131 loc) · 5.82 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Groovy Module Fixer</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f5f6;
}
#drop-zone {
width: calc(100vw - 60px);
height: calc(100vh - 60px);
border: 10px dashed #b9b9b9;
border-radius: 20px;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
font-size: 3em;
font-weight: bold;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
color: #b9b9b9;
}
#drop-zone.hover {
color: #0066ff;
border: 10px dashed #0066ff;
}
#drop-zone.processed {
color: #81ae49;
border: 10px solid #81ae49;
font-size: 2em;
}
</style>
</head>
<body>
<div id="drop-zone">
Drop a Module JSON file
</div>
<script type="module">
import * as GroovyRemix from "/js/LMGroovyRemix.mjs";
const dropZone = document.getElementById('drop-zone');
dropZone.addEventListener('dragover', function(e) {
e.preventDefault();
dropZone.classList.remove('processed');
dropZone.classList.add('hover');
dropZone.innerText = "Drop a Module JSON file"
});
dropZone.addEventListener('dragleave', function() {
dropZone.classList.remove('hover');
});
function applyFixes(fixNames, fixType, script) {
for (const patch of GroovyRemix.getPatches()) {
if(script.match(patch.check)) {
if(patch.rgx.global) {
script = script.replaceAll(patch.rgx, patch.str);
} else {
script = script.replace(patch.rgx, patch.str);
}
fixNames.push(`${patch.name}${fixType}`);
}
}
return script
}
dropZone.addEventListener('drop', function(e) {
e.preventDefault();
dropZone.classList.remove('hover');
let multiMode = event.dataTransfer.files.length > 1;
for(const file of event.dataTransfer.files) {
if (file && file.type === "application/json") {
const reader = new FileReader();
reader.onload = function(e) {
//try {
const jsonData = JSON.parse(e.target.result);
let fixNames = [];
if(jsonData?.activeDiscovery?.params?.type == "groovy") {
jsonData.activeDiscovery.params.content = applyFixes(fixNames, " (Discover)", jsonData.activeDiscovery.params.content);
}
if(jsonData?.collectionAttrs) {
if(jsonData?.collectionAttrs?.type) {
if(jsonData?.collectionAttrs?.type == "groovy") {
jsonData.collectionAttrs.content = applyFixes(fixNames, " (Collect)", jsonData.collectionAttrs.content);
}
} else {
for(const attr of jsonData?.collectionAttrs) {
if(attr?.script?.type == "groovy") {
attr.script.content = applyFixes(fixNames, " (Collect)", attr.script.content);
}
}
}
}
if(jsonData?.script?.type == "groovy") {
jsonData.script.content = applyFixes(fixNames, " (Main Script)", jsonData.script.content);
}
if(fixNames.length != 0) {
if(!dropZone.innerText.startsWith("Issues Resolved")) {
dropZone.innerText = "Issues Resolved\n\n"
}
if(multiMode) {
dropZone.innerText += file.name + " Fixed\n"
} else {
dropZone.innerText += fixNames.join("\n")
}
const jsonString = JSON.stringify(jsonData, null, 2);
const link = document.createElement('a');
link.href = URL.createObjectURL(new Blob([jsonString], { type: 'application/json' }));
link.download = file.name.replace(/(\.\w*$)/, ".V4$1");
link.click();
} else {
dropZone.innerText = "No Issues Detected!"
}
dropZone.classList.add('processed');
//} catch (err) {
// console.error('Invalid JSON:', err);
//}
};
reader.readAsText(file);
} else {
console.log('Invalid JSON file.');
}
}
});
</script>
</body>
</html>