-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (70 loc) · 3.11 KB
/
index.js
File metadata and controls
83 lines (70 loc) · 3.11 KB
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
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
var urls = []
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const downloadMetadata = () => {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:json/plain/* margin: 0 auto; */;charset=utf-8,' +
encodeURIComponent(JSON.stringify(urls)));
pom.setAttribute('download', `${document.title.replace(/\s/g, '')}.json`);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);
}
const getData = async (overlay, text, stopExecution) => {
const searchArea = document.querySelector("[data-cid]");
const imgs = searchArea.getElementsByTagName("img")
var i;
var total = 0;
for (i = 0; i < imgs.length; i++) {
total += 1
if (stopExecution.value) {
break;
}
if (imgs[i].width <= 100) {
continue
}
imgs[i].click()
text.innerHTML = `Parsing Images...[ ${total} ]`
await sleep(message.speed * 1000).then(() => {
var el = document.querySelector("[style='opacity: 1;']")
urls.push(el.getElementsByTagName("img")[1].src)
})
}
enableScrolling()
overlay.remove()
downloadMetadata()
}
const disableScrolling = () => {
var x = window.scrollX;
var y = window.scrollY;
window.onscroll = function () { window.scrollTo(x, y); };
}
const enableScrolling = () => {
window.onscroll = function () { };
}
if (message.action === "download") {
var overlay = document.createElement('div')
var btn = document.createElement('button')
var text = document.createElement('div')
overlay.setAttribute("id", "pgd_overlay")
text.setAttribute("style", "color: white; padding-top: 25%; font-size: 55px; justify-content: center; align-items: center;text-align: center; vertical-align: middle;")
btn.setAttribute("style", "margin-top: 30px; margin-left: calc(50% - 150px); border-radius: 25px; color: dimgrey; font-size: 40px; justify-content: center; align-items: center; text-align: center; vertical-align: middle; width: 300px; background-color: aliceblue;")
text.innerHTML = "Parsing Images...[ 0% ]"
btn.innerHTML = "Stop Parsing"
overlay.setAttribute("style", "overflow: hidden; position: fixed; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.7); z-index: 999; cursor: pointer;")
disableScrolling()
overlay.appendChild(text)
overlay.appendChild(btn)
document.body.appendChild(overlay)
var stopExecution = { value: false }
getData(overlay, text, stopExecution)
btn.addEventListener('click', event => {
btn.innerHTML = "Please wait..."
btn.disabled = true;
stopExecution.value = true
});
}
});