-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeNode.mjs
66 lines (50 loc) · 2.07 KB
/
changeNode.mjs
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
(function () {
const getElement = (parentElement, className) => {
return [...(parentElement.children)].find(child => {
return child.classList.contains(className);
});
}
if (!window.monaco)
throw new Error("MonacoEditor not loaded");
var historyNodes = [...window.document.getElementsByClassName("changehistory")]
historyNodes.forEach(history => {
let node;
try {
node = history.children[0].children[1].children[0];
} catch (e) {
node = history.children[0].children[0].children[0];
}
var oldText = getElement(node, "activity-old-val").innerText;
var currentText = getElement(node, "activity-new-val").innerText;
const newDivNodeId = Math.random().toString(36).substring(2);
const checkboxInline = document.createElement("input");
checkboxInline.type = "checkbox";
checkboxInline.id = `checkbox-${newDivNodeId}`;
const labelDiv = document.createElement("label");
labelDiv.innerText = "Inline Diff";
labelDiv.appendChild(checkboxInline);
const divNode = document.createElement("div");
divNode.style.width = "1500px";
divNode.style.height = "400px";
divNode.style.display = "block";
divNode.id = newDivNodeId;
history.replaceChildren(labelDiv, divNode);
const diffEditor = window.monaco.editor.createDiffEditor(divNode, {
enableSplitViewResizing: true,
renderSideBySide: true,
automaticLayout: true
});
checkboxInline.addEventListener('change', function () {
diffEditor.updateOptions({
renderSideBySide: !this.checked
});
});
var lhsModel = window.monaco.editor.createModel(oldText, 'markdown');
var rhsModel = window.monaco.editor.createModel(currentText, 'markdown');
diffEditor.setModel({
original: lhsModel,
modified: rhsModel
});
window.monaco.editor.createDiffNavigator(diffEditor).next()
})
})();