-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
75 lines (48 loc) · 2.31 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// content.js
chrome.storage.sync.get('display_mode', function(data) {
// console.log('display: ' + data.display_mode);
extensionMode = data.display_mode;
decoratePage(extensionMode);
});
function decoratePage(extensionMode) {
// console.log('extensionMode: ' + extensionMode);
if(extensionMode != 'disabled') {
// get all images
var allImages = $('img');
var regex = /\/full\/[\!0-9]*,[\!0-9]*\/\d*\/.*\.jpg/;
var iconPNG = chrome.extension.getURL("images/eye32.png");
var iconSVG = chrome.extension.getURL("images/eye.svg");
// loop over images and check for iiif pattern in src
$.each( allImages, function( index, image ){
var src = $(image).attr('src');
if (src.match(regex)) {
// replace with info json
var infoJSON = src.replace(regex, "/info.json");
// is parent an 'a' tag?
var parentElement = $(image).parent();
// add the link to the DOM
if($(parentElement).is("a")) {
$(parentElement).after("<a id='slowlookinglink_" + index + "' class='slowlookinglink' href='http://slowlooking.cogapp.com/?image=" + infoJSON + "' target='_blank'><img src='" + iconPNG + "' /></a>");
}
else {
$(image).after("<a id='slowlookinglink_" + index + "' class='slowlookinglink' href='http://slowlooking.cogapp.com/?image=" + infoJSON + "' target='_blank'><img src='" + iconPNG + "' /></a>");
}
if(extensionMode == 'unobtrusive') {
$("#slowlookinglink_" + index).hide();
$(image).mouseenter(function() {
$("#slowlookinglink_" + index).show();
});
$("#slowlookinglink_" + index).mouseenter(function() {
$("#slowlookinglink_" + index).show();
});
$(image).mouseleave(function() {
$("#slowlookinglink_" + index).hide();
});
$("#slowlookinglink_" + index).mouseleave(function() {
$("#slowlookinglink_" + index).hide();
});
}
}
});
}
}