-
Notifications
You must be signed in to change notification settings - Fork 0
/
exif.swig
29 lines (28 loc) · 897 Bytes
/
exif.swig
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
<script>
function getExif(target) {
const tags = {{ config.exif.tags | json }};
EXIF.getData(target, function() {
let result = [];
for (let [key, value] of Object.entries(tags)) {
let data = EXIF.getTag(this, key);
if (key === 'ExposureTime' && data <= 0.25) {
data = '1/' + parseInt(1 / data);
}
if (data) result.push(value.replace('{value}', data));
}
if (result.length > 0) {
const box = document.createElement('div');
target.wrap(box);
box.classList.add('exif-container');
box.insertAdjacentHTML('beforeend', `<div class="exif-metabar"><span>${result.join(' ')}</span></div>`);
}
});
}
[...document.querySelectorAll('.post-body img')].forEach(element => {
if (element.complete) getExif(element);
// `lazyload` compatible
element.addEventListener('load', () => {
getExif(element);
});
});
</script>