-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif.js
40 lines (37 loc) · 1.17 KB
/
exif.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
(function() {
async function getExif(element) {
const template = CONFIG.exif;
const tags = await ExifReader.load(element.src);
let result = template;
for (let [key, value] of Object.entries(tags)) {
if (key === 'ApertureValue') {
value.description = Number(value.description).toFixed(1);
}
if (key === 'FocalLength') {
if (tags.FocalLengthIn35mmFilm) {
value.description = tags.FocalLengthIn35mmFilm.description;
}
}
result = result.replace(`{${key}}`, value.description);
}
if (result !== template) {
const box = document.createElement('div');
element.wrap(box);
box.classList.add('exif-container');
box.insertAdjacentHTML('beforeend', `<div class="exif-metabar"><span>${result}</span></div>`);
}
}
function getAllExif() {
[...document.querySelectorAll('.post-body img')].forEach(element => {
if (element.complete) getExif(element);
// `lazyload` compatible
element.addEventListener('load', () => {
getExif(element);
});
});
}
getAllExif();
document.addEventListener('pjax:success', () => {
getAllExif();
});
})();