-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
66 lines (61 loc) · 6.65 KB
/
contentScript.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
(function () {
function fileExtension(url) {
return url.split(/[#?]/)[0].split(".").pop().trim();
}
function downloadURI(uri, name) {
fetch(uri)
.then((resp) => resp.blob())
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});
}
let downloadButton = document.createElement("IMG");
downloadButton.src =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIYAAACGCAMAAAAvpwKjAAAAb1BMVEX///8AAAD+/v719fX09PT9/f0EBAT8/Pz29vb7+/v39/cDAwP6+vr5+fn4+PgBAQFQUFDd3d1LS0vu7u7X19efn5+lpaUjIyM+Pj7Pz8+2trY5OTmHh4cxMTEMDAyPj49fX1/FxcUZGRl6enptbW3cppuQAAANyUlEQVR4nL1c63rbOA6lbtbFkmzZTprJtE266fs/4xIACYIQKSnZfOsfmimtQBAOAJ5DMjHGfhq8lPZS4qVJDZY8iP/bqMHwDf54+vakYfy3/UzwP2NrL30Pd0z225IGex4cDQ/ynS0Ojnh7629vex4cw+0j2kgMtlNJXnTwc/MMX3Z2qK3gZhwcJhgcjB+s4Ic7+OEJBnsYbOrGDw5gowcbTdV4w2SjQxsN2OBBtNF2MGjtTjDegYWpAjM1PLBODDY1eFGBhQG9qMEMelGNfnDkQWcDBifwogk20PA88NPm0jSNfw98oHOZb0YLLVrA9+gmtoCxgDvLLnjBASrRNWejdDbKYCPEs6xcdgQL9B4Vx2KszNrC3AVEWj84xDCVIkBVHKBBvB4Oti45+IG9iCbf7GAKD+RBQgQHuxQiIsjhgQqRxns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";
downloadButton.style.borderRadius = "50%";
downloadButton.style.padding = "8px";
downloadButton.style.cursor = "pointer";
downloadButton.addEventListener("contextmenu", (event) =>
event.preventDefault()
);
downloadButton.addEventListener("click", (e) => {
let medias = document.querySelectorAll(
"article.M9sTE.L_LMM ._97aPb .KL4Bh .FFVAD"
);
if (medias.length === 0) {
medias = document.querySelectorAll("article.M9sTE.L_LMM ._97aPb .tWeCl");
}
const pagename = document.querySelector("a.sqdOP.yWX7d._8A5w5.ZIAjV ")
.innerText;
medias.forEach((media) => {
const ext = fileExtension(media.src);
downloadURI(media.src, pagename + ext);
});
});
function handleCanvas(sec) {
if (sec.children.length === 4) {
sec.insertBefore(downloadButton, sec.children[0]);
}
}
const observer = new MutationObserver(function (mutations, me) {
const sec = document.querySelector("section.ltpMr.Slqrh");
if (sec) {
handleCanvas(sec);
me.disconnect();
return;
}
});
observer.observe(document, {
childList: true,
subtree: true,
});
})();