-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_google_urls.js
57 lines (51 loc) · 1.61 KB
/
get_google_urls.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
let simulateRightClick = element => {
const eventInitDict = {
bubbles: true,
cancelable: false,
view: window,
button: 2,
buttons: 2,
clientX: element.getBoundingClientRect().x,
clientY: element.getBoundingClientRect().y,
};
element.dispatchEvent(new MouseEvent('mousedown', eventInitDict));
element.dispatchEvent(new MouseEvent('mouseup', eventInitDict));
element.dispatchEvent(new MouseEvent('contextmenu', eventInitDict));
};
let getURLParam = (queryString, key) => {
let vars = queryString.replace(/^\?/, '').split('&');
for (let i = 0; i < vars.length; ++i) {
let pair = vars[i].split('=');
if (pair[0] == key) return pair[1];
}
return false;
};
let createDownload = contents => {
const hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' + encodeURI(contents);
hiddenElement.target = '_blank';
hiddenElement.download = 'urls.txt';
hiddenElement.click();
};
let grabUrls = () => {
let urls = [];
return new Promise((resolve, reject) => {
let listUrls = document.querySelectorAll('.isv-r a:first-of-type');
let index = 0;
listUrls.forEach(element => {
simulateRightClick(element.querySelector('img'));
var interval = setInterval(() => {
if (element.href.trim() !== '') {
clearInterval(interval);
let googleUrl = element.href.replace(/.*(\?)/, '$1');
fullImageUrl = decodeURIComponent(
getURLParam(googleUrl, 'imgurl')
);
if (fullImageUrl !== 'false') urls.push(fullImageUrl);
if (++index == listUrls.length - 1) resolve(urls);
}
}, 10);
});
});
};
grabUrls().then(urls => createDownload(urls.join('\n')));