-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadpedigreetest.js
153 lines (133 loc) · 6.4 KB
/
uploadpedigreetest.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
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
var fi = document.createElement("input")
fi.type = "file"
fi.accept = "application/json"
document.body.appendChild(fi)
fi.click()
fi.onchange = () => {
var file = fi.files[0]
fi.remove()
var reader = new FileReader()
reader.onload = async (e) => {
window.appendLoadingFront = () => {
if (document.getElementById("loadingFront") == null) {
window.loadingFront = document.createElement("div");
loadingFront.style = "pointer-events: none; background-color: rgba(0, 0, 0, .2); width: 100%; height: 100%; position: absolute; z-index: 9999999999999999; left: 0; top: 0;"
loadingFront.id = "loadingFront";
loadingFront.innerHTML = "<h1 id='dotdotdot' style=\"font-family: 'Gill Sans', sans-serif; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);\">LOADING</h1>"
window.changeDot = () => {
var dotdotdot = document.getElementById("dotdotdot");
var dots = ["LOADING", "LOADING.", "LOADING..", "LOADING..."]
var dotIndex = dots.indexOf(dotdotdot.textContent)
if (dotIndex === 3) dotIndex = -1;
dotdotdot.textContent = dots[dotIndex + 1]
}
window.dotDotDotInterval = setInterval(changeDot, 1000)
document.body.appendChild(loadingFront);
console.log("Not good");
} else {
console.log("loadingFront All Good.");
}
}
//setTimeout(appendLoadingFront, 0);
window.fsPedigree = document.querySelector("#main-content-section > tree-app").shadowRoot.querySelector("#pages > tree-pedigree").shadowRoot.querySelector("#pedigree");
window.customState = JSON.parse(e.target.result);
window.ROOT = customState.ROOT[1];
delete customState.ROOT[1];
delete customState.DESCROOT[1];
window.ahnentafelsToClick = { "root": Object.keys(customState.ROOT).sort(e => e), "descroot": Object.keys(customState.DESCROOT).sort(e => e) };
window.coupleIdsToClick = { "root": Object.keys(customState.ROOT).map((e, i) => customState.ROOT[ahnentafelsToClick.root[i]]), "descroot": Object.keys(customState.DESCROOT).map((e, i) => customState.DESCROOT[ahnentafelsToClick.descroot[i]]) };
window.ahnentafelsToClickFreeze = structuredClone(ahnentafelsToClick);
window.coupleIdsToClickFreeze = structuredClone(coupleIdsToClick);
window.couplesToClick = { "root": false, "descroot": false };
var didroot = await doRoot();
alert("did root ", didroot);
}
reader.onerror = (e) => {
alert(e.target.error.name)
}
reader.readAsText(file)
}
function updateRootCouplesToClick() {
return new Promise((resolve, reject) => {
Array.from(coupleIdsToClick.root).forEach((coupleId, i) => {
var coupleShadowParentUnfiltered = Array.from(document.querySelector("#main-content-section > tree-app")
.shadowRoot.querySelector("#pages > tree-pedigree")
.shadowRoot.querySelector("#pedigree")
.shadowRoot.querySelector("#pedigree > div:nth-child(1)")
.querySelectorAll("pedigree-couple-renderer[data-test-couple-ahnentafel]"));
var coupleShadowParent = coupleShadowParentUnfiltered.filter(e =>
e.coupleId.includes(coupleId) && e.coupleId.length < coupleId.length + 3
)[0];
if (coupleShadowParent == undefined) {
coupleShadowParent = [];
coupleShadowParentUnfiltered.forEach(e => {
if (e.coupleId.split("_")[0] == coupleId.split("_")[0] || e.coupleId.split("_")[1] == coupleId.split("_")[1]) {
coupleShadowParent.push(e);
}
});
coupleShadowParent = coupleShadowParent[0];
}
if (coupleShadowParent) {
// console.log(coupleShadowParent);
var couple = false;
try {
couple = coupleShadowParent.shadowRoot.querySelector("div.couple-wrapper");
// console.log("couple: ");
// console.log(couple);
} catch (e) {
alert("something is bad with your saved pedigree, maybe they changed something... sorry.");
reject(e);
}
// console.log(coupleShadowParent.coupleId);
// console.log("coupleid ", coupleId)
var button = couple.querySelector("button.append-pedigree");
//console.log(button)
if (button.ariaLabel.includes("Expand")) {
couplesToClick.root = couple;
// console.log("button has expand")
couplesToClick.rootCoupleId = coupleId;
resolve(couplesToClick);
} else {
var index = coupleIdsToClick.root.indexOf(coupleId);
ahnentafelsToClick.root.splice(index, 1);
coupleIdsToClick.root.splice(index, 1);
// console.log("button doesn't have expand")
}
}
});
});
}
function clickNextRootCouple() {
return new Promise((resolve) => {
var button = couplesToClick.root.querySelector("button.append-pedigree");
button.click();
var config = { attributes: true, subtree: false, childList: false };
var mutationCallback = (mutations) => {
mutations.forEach(m => {
if (m.attributeName == "aria-expanded") {
resolve();
}
})
};
var observer = new MutationObserver(mutationCallback);
observer.observe(button, config);
})
}
function doRoot() {
return new Promise(async (resolve) => {
for (var i = 0; i < 5; i++) {
fsPedigree.pedigreeClass.pedigreeEl
.transition()
.duration(1)
.call(fsPedigree.pedigreeClass.zoom.scaleBy, .2);
}
couplesToClick = { "root": false, "descroot": false };
var nextCouple = await updateRootCouplesToClick();
console.log(nextCouple.rootCoupleId);
await clickNextRootCouple();
if (coupleIdsToClick.root.length) {
await doRoot();
resolve(true)
}
});
}