-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathopr_show_exif_info.user.js
77 lines (71 loc) · 3.71 KB
/
opr_show_exif_info.user.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
// ==UserScript==
// @name Wayfarer Show EXIF Info
// @version 0.6
// @namespace https://github.com/DeepAQ/SmartIntel
// @description Show EXIF info of photos , if available, in Wayfarer
// @match *://wayfarer.nianticlabs.com/review
// @require https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js
// @require https://github.com/mattiasw/ExifReader/releases/download/2.7.0/exif-reader.js
// ==/UserScript==
(function() {
var tagsToShow = ['DateTime', 'Make', 'Model', 'Software'];
var distance = function (lat1, lng1, lat2, lng2) {
var dx = Math.abs(lng1 - lng2);
var dy = Math.abs(lat1 - lat2);
var b = (lat1 + lat2) / 2.0;
var lx = (dx / 180.0 * Math.PI) * 6367000.0 * Math.cos(b / 180.0 * Math.PI);
var ly = 6367000.0 * dy / 180.0 * Math.PI;
return (lat1 < lat2 ? '⇑' : '⇓') + Math.ceil(ly) + 'm ' + (lng1 < lng2 ? '⇒' : '⇐') + Math.ceil(lx) + 'm';
};
var getExif = function (url) {
console.log('[EXIF] Downloading full size photo...');
fetch(url).then(function (req) {
return req.arrayBuffer();
}).then(function (buf) {
var info = '';
try {
var tags = ExifReader.load(buf);
console.log('[EXIF] tags:');
console.log(tags);
for (var key in tagsToShow) {
if (tags[tagsToShow[key]]) {
info += tagsToShow[key] + ': ' + tags[tagsToShow[key]].description;
if (tagsToShow[key] == 'GPSLatitude' || tagsToShow[key] == 'GPSLongitude') {
var ref = tags[tagsToShow[key] + 'Ref'].value[0];
var negative = (ref == 'S' || ref == 'W');
info += ref + ' (' + (negative ? -1 : 1) * tags[tagsToShow[key]].description + ')';
}
info += '<br />';
}
}
if (tags['GPSLatitude'] && tags['GPSLongitude']) {
var deglat = (tags['GPSLatitudeRef'].value[0] == 'S' ? -1 : 1) * tags['GPSLatitude'].description;
var deglon = (tags['GPSLongitudeRef'].value[0] == 'W' ? -1 : 1) * tags['GPSLongitude'].description;
info += 'GPSLatitude: ' + deglat + '<br />GPSLongitude: ' + deglon + '<br />';
var portalPos = /@([^,]+),([^,]+)$/.exec(document.evaluate("//*[@ng-bind='subCtrl.pageData.streetAddress']/parent::a").iterateNext().search);
var portalLat = Number(portalPos[1]);
var portalLng = Number(portalPos[2]);
info += 'Distance (portal -> photo): ' + distance(portalLat, portalLng, deglat, deglon) + '<br />';
// info += '<div class="btn-group"><a class="button btn btn-default" target="osm" href="https://www.openstreetmap.org/?mlat=' + deglat + '&mlon=' + deglon + '&zoom=15">Open in OSM</a></div>';
}
} catch (e) {}
if (info !== '') {
info = '<small class="gold">[EXIF]</small><br>' + info;
} else {
info = '<small class="gold">[EXIF]</small><br />No EXIF data present';
}
$('#descriptionDiv').append('<div>' + info + '</div>');
});
};
var tryGetImgUrl = function () {
var url = $('.center-cropped-img').attr('src');
if (!url) {
console.log('[EXIF] Waiting for photo to be loaded...');
setTimeout(tryGetImgUrl, 1000);
} else {
console.log('[EXIF] Photo URL: ' + url);
getExif((url + '=s0').replace('http:', 'https:'));
}
};
tryGetImgUrl();
})();