-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
56 lines (44 loc) · 1.21 KB
/
content.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
/* global ImgData */
/* global EXIF */
var elementGlobal;
document.addEventListener('contextmenu', contextMenuOpened, true);
browser.runtime.onMessage.addListener(notify);
function contextMenuOpened(event) {
elementGlobal = event.target;
}
function notify(request) {
if (request === 'ImgPropertiesClicked')
retrieveImageData();
if (request === 'MenuHidden')
clean();
}
function retrieveImageData() {
let element = elementGlobal;
if (element === undefined)
return false;
try {
let scaleRatio = window.devicePixelRatio;
let imgData = new ImgData(element, scaleRatio);
imgData.retrieveData()
.then ((properties) => {
EXIF.getData(element, function() {
let exifTags = EXIF.getAllTags(this);
let iptcTags = EXIF.getAllIptcTags(this);
browser.storage.local.set({
'ipImageProperties': properties,
'ipImageEXIF': JSON.stringify(exifTags),
'ipImageIPTC': JSON.stringify(iptcTags)
})
.then(() => {
browser.runtime.sendMessage('ImgDataFinished');
});
})
})
}
catch (error) {
console.error('ImageProperties Error: ' + error.message);
}
}
function clean() {
elementGlobal = undefined;
}