forked from lovmoon3k/useful-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsta_getAllImagesInUserProfile.js
76 lines (75 loc) · 2.37 KB
/
insta_getAllImagesInUserProfile.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
export default {
name: {
en: "Get all images in insta user profile",
vi: "Tải tất cả ảnh insta user profile",
},
description: {
en: "Get all images in user profile",
vi: "Tải tất cả ảnh có trong profile của user bất kỳ",
},
blackList: [],
whiteList: ["*://*.instagram.com"],
func: async function () {
const WAIT_FOR_MODAL_IMG_LOAD = 5000;
const FIND_IMG_IN_MODAL_INTERVAL = 100;
const getOriginalVideoFromBlob = (videoEl) => {
const instanceKey = Object.keys(videoEl).find((key) =>
key.includes("Instance")
);
const $react = videoEl[instanceKey];
const videoLink = $react.return.memoizedProps.fallbackSrc;
return videoLink;
};
const getAllClickableDiv = () =>
Array.from(document.querySelectorAll("div._9AhH0")) || [];
const getMediaInViewport = () =>
document.querySelector("article[role='presentation'] div.KL4Bh>img") ||
document.querySelector("article[role='presentation'] div.E-66r>video");
const sleep = (milliseconds) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};
window.onblur = function () {
has_focus = false;
};
window.onfocus = function () {
has_focus = true;
};
let has_focus = true;
const queue = getAllClickableDiv();
const done = [];
const urls = [];
while (queue.length > 0) {
const first = queue.shift();
first.scrollIntoView();
first.click();
done.push(first);
const new_img = getAllClickableDiv().filter(
(_) => done.indexOf(_) == -1 && queue.indexOf(_) == -1
);
queue.push(...new_img);
let media;
let limit = WAIT_FOR_MODAL_IMG_LOAD / FIND_IMG_IN_MODAL_INTERVAL;
while ((!media && limit > 0) || !has_focus) {
media = getMediaInViewport();
limit--;
await sleep(FIND_IMG_IN_MODAL_INTERVAL);
}
if (media) {
console.log(media.tagName);
if (media.tagName == "VIDEO") {
const url = getOriginalVideoFromBlob(media);
urls.push(url);
console.log(url);
window.open(url);
window.focus();
}
if (media.tagName == "IMG") {
urls.push(media.src);
console.log(media.src);
}
}
document.querySelector("div.Igw0E>button.wpO6b")?.click();
}
console.log(urls);
},
};