-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgrab_images.js
50 lines (40 loc) · 1.15 KB
/
grab_images.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
var images_to_send = [];
var send_images = function () {
chrome.extension.sendRequest({
action: 'add_images',
image_urls: images_to_send,
});
};
var add_image = function (image_url) {
if (typeof image_url === 'undefined' || !image_url || !$.trim(image_url)) {
return;
}
images_to_send.push(image_url);
};
var get_url_from_background_image = function (el) {
el = $(el);
var url = el.css('background-image');
if (url === 'none' || !url.match(/^url\s*\(/)) {
return;
}
function check_position (pos) {
// Checks that there's no offset.
return pos.match(/^0\s*\D*$/);
}
if (!check_position(el.css('background-position-x')) || !check_position(el.css('background-position-y'))) {
return;
}
return url.replace(/^url\s*\(["']?/, '').replace(/["']?\)$/, '');
};
$(function () {
// Image tags.
$('img:visible').each(function (_, img) {
add_image($(img).get(0).src);
});
// Background images.
$('*:visible').each(function (_, el) {
var url = get_url_from_background_image(el);
add_image(url);
});
send_images();
});