-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
103 lines (100 loc) · 3.14 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
chrome.runtime.sendMessage(
{
message: 'ack'
},
function(response) {
return true;
}
);
window.onbeforeunload = function() {
chrome.runtime.sendMessage(
{
message: 'unload'
},
function(response) {
return true;
}
);
};
// Expand listener
chrome.runtime.onMessage.addListener (
function (request, sender, sendResponse) {
if (chrome.extension.lastError)
console.log('Error: ' + chrome.runtime.lastError.message);
if (request.op === 'expand') {
var expandItems = [];
expandItems = expandItems.concat($('.gallery .project a.project-image').map(function(i, el) {
return $(el).attr('href');
}).get());
expandItems = expandItems.concat($('.more-artworks .visible-sm a.additional-artwork').map(function(i, el) {
return $(el).attr('href');
}).get());
expandItems = expandItems.concat($('.more-album-grid .album-grid-item a').map(function(i, el) {
return $(el).attr('href');
}).get());
sendResponse (
{
'id': request.id,
'url': window.location.href,
'expandItems': expandItems,
'debug': true
}
);
return true;
}
}
);
// Download listener
chrome.runtime.onMessage.addListener (
function (request, sender, sendResponse) {
if (chrome.extension.lastError)
console.log('Error: ' + chrome.runtime.lastError.message);
if (request.op === 'download') {
if (window.location.href.indexOf('/artwork/') < 0){
sendResponse (
{
'id': request.id,
'url': window.location.href,
'isArt': false,
'debug': true
}
);
return true;
} else {
var authorName = $('.name > a').attr('href');
if (authorName) authorName = authorName.replace('/', '');
var imageList = $('.artwork-image img').map(function(i, el) {
return $(el).attr('ng-src');
}).get();
var rxTags = {
'category': '',
'mature': false,
'discovery': $('.tags a.label').map(function(i, el) {
return $(el).text();
}).get(),
'software': $('.software p').map(function(i, el) {
return $(el).text();
}).get()
};
sendResponse(
{
'id': request.id,
'url': window.location.href,
'isArt': true,
'debug': true,
'author': authorName,
'title': $('.artwork-info-container .h3').text(),
'imageList': imageList,
'tags': rxTags
}
);
return true;
}
}
// var rxGoodName = new RegExp(/[A-Z,a-z,0-9]+_by_[A-Z,a-z,0-9]+/);
// var rxToULine = new RegExp(/[_,\s,-]/g);
// var rxAuthorURL = new RegExp(/(?:_by_)([A-Z,a-z]+)(?:-)/);
// var uri = new URI(imageLink);
// properFileName = imageName.replace(/[^A-Za-z0-9]/gi, '_') + '_by_' +
}
);