-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.html
173 lines (152 loc) · 4.48 KB
/
popup.html
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<title>Annotations</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<style type="text/css">
@charset "UTF-8";
@font-face {
font-family: "brill";
src: url("fonts/brill-roman.ttf");
font-weight: normal;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "brill";
src: url("fonts/brill-bold.ttf");
font-weight: bold;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "brill";
src: url("fonts/brill-italic.ttf");
font-weight: normal;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "brill";
src: url("fonts/brill-bold-italic.ttf");
font-weight: bold;
font-style: italic;
font-display: swap;
}
body {
font-family: 'brill', serif;
color: black;
max-width: 100vw;
max-height: 100vh;
margin: 2em;
line-height: 1.2;
font-size: 1.5em;
letter-spacing: 0;
position: relative;
padding: 0;
background: rgb(232,232,231);
display: flex;
align-items: center;
flex-direction: column;
}
img {
padding: 3px;
}
tr:hover {
background: rgba(180,184,196,0.8);
}
#addbutton {
display: none;
}
#savebutton, #addtext {
cursor: pointer;
}
#savebutton:hover, #addtext:hover {
text-decoration: underline;
}
#content img {
height: 100px;
}
</style>
<script type="text/javascript">
function load() {
const imported = window.imported;
const an = imported.an;
const glyphSort = imported.glyphSort;
const displayCrops = imported.displayCrops;
document.getElementById('savebutton').addEventListener('click',saveAnnotations);
document.getElementById('addbutton').addEventListener('change',appendAnnotations);
document.getElementById('addtext').addEventListener('click',function() {
document.getElementById('addbutton').click();
});
const header = document.querySelector('h2');
header.append(imported.title);
displayCrops(document.getElementById('content'),true,an);
};
const saveAnnotations = function() {
const docclone = document.cloneNode(true);
docclone.querySelector('script').remove();
docclone.querySelector('.topmenu').remove();
//const serializer = new XMLSerializer();
//const str = serializer.serializeToString(docclone);
const str = docclone.documentElement.outerHTML;
const file = new Blob([str],{type: 'text/html;charset=utf-8'});
imported.FileSaver(file,`${imported.title}.html`);
};
const appendAnnotations = function(e) {
const f = e.target.files[0];
const loadHTMLAnnos = function(e) {
const domtree = (new DOMParser()).parseFromString(e.target.result,'text/html');
const oldh2 = document.querySelector('h2');
const newh2 = domtree.querySelector('h2');
if(newh2) {
oldh2.appendChild(document.createElement('br'));
oldh2.append(newh2.textContent);
}
const newrows = domtree.querySelectorAll('tr');
const table = document.querySelector('table');
const oldrows = new Map(
[...table.querySelectorAll('tr')].map(r => {
const th = r.querySelector('th').textContent;
const td = r.querySelector('td');
return [th,td];
})
);
for(const n of newrows) {
const th = n.querySelector('th').textContent;
const td = n.querySelector('td');
if(oldrows.has(th)) {
const par = oldrows.get(th);
while(td.firstChild)
par.appendChild(td.firstChild);
}
else {
table.appendChild(n);
}
}
const allrows = new Map(
[...table.querySelectorAll('tr')].map(r => {
const th = r.querySelector('th').textContent;
return [th,r];
})
);
const sorted = [...allrows.keys()].sort(glyphSort);
for(const s of sorted)
table.appendChild(allrows.get(s));
};
const reader = new FileReader();
reader.onload = loadHTMLAnnos;
reader.readAsText(f);
};
</script>
</head>
<body>
<div class="topmenu">
<div id="savebutton">save annotations</div>
<div id="addtext">append annotations</div>
<div><input id="addbutton" type="file" accept=".html,text/html"></div>
</div>
<h2></h2>
<div id="content">
</div>
</body>
</html>