-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
fb_storySaver.js
116 lines (109 loc) · 3.97 KB
/
fb_storySaver.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
104
105
106
107
108
109
110
111
112
113
114
115
116
import { UfsGlobal } from "./content-scripts/ufs_global.js";
export default {
icon: "https://lh3.googleusercontent.com/e8gqesNOLhN-0xivFcaAlwGaoftfxEJcZXcXJ1F2bhoqrozs3mCYgLhPC0qJ9izdGYRnHwfXegimH9fjj3IBwlby9ZA=w128-h128-e365-rj-sc0x00ffffff",
name: {
en: "Download watching fb Story/Comment",
vi: "Tải Story/Comment fb đang xem",
},
description: {
en: "Download facebook story / comment video that you are watching",
vi: "Tải facebook story / video bình luận bạn đang xem",
},
pageScript: {
onClick: function () {
// Source code extracted from: https://chrome.google.com/webstore/detail/story-saver/mafcolokinicfdmlidhaebadidhdehpk
let videos = document.querySelectorAll("video");
let listUrls = [];
for (let i = videos.length - 1; i >= 0; i--) {
if (videos[i].offsetHeight === 0) continue;
let reactKey = "";
let keys = Object.keys(videos[i]);
for (let j = 0; j < keys.length; j++) {
if (keys[j].indexOf("__reactFiber") != -1) {
reactKey = keys[j].split("__reactFiber")[1];
break;
}
}
let storyUrl;
try {
storyUrl =
videos[i].parentElement.parentElement.parentElement.parentElement[
"__reactProps" + reactKey
].children[0].props.children.props.implementations[1].data.hdSrc;
} catch (e) {}
if (storyUrl == null) {
try {
storyUrl =
videos[i].parentElement.parentElement.parentElement.parentElement[
"__reactProps" + reactKey
].children[0].props.children.props.implementations[1].data.sdSrc;
} catch (e) {}
}
if (storyUrl == null) {
try {
storyUrl =
videos[i].parentElement.parentElement.parentElement.parentElement[
"__reactProps" + reactKey
].children.props.children.props.implementations[1].data.hdSrc;
} catch (e) {}
}
if (storyUrl == null) {
try {
storyUrl =
videos[i].parentElement.parentElement.parentElement.parentElement[
"__reactProps" + reactKey
].children.props.children.props.implementations[1].data.sdSrc;
} catch (e) {}
}
if (storyUrl == null) {
try {
storyUrl =
videos[i]["__reactFiber" + reactKey].return.stateNode.props
.videoData.$1.hd_src;
} catch (e) {}
}
if (storyUrl == null) {
try {
storyUrl =
videos[i]["__reactFiber" + reactKey].return.stateNode.props
.videoData.$1.sd_src;
} catch (e) {}
}
if (storyUrl != null) {
listUrls.push({ url: storyUrl, type: "video" });
}
}
let storyImgUrl = Array.from(
document.querySelectorAll('img[draggable="false"]')
).find((_) => _.alt)?.src;
if (storyImgUrl) {
listUrls.push({ url: storyImgUrl, type: "img" });
}
let profile_pic = document.querySelector(
"a[role=link][tabindex='0'][href*='https://www.facebook']>img"
);
let username = profile_pic?.alt || "fb_story";
if (!listUrls.length) {
alert("Không tìm thấy facebook story nào trong trang web.");
} else if (listUrls.length === 1) {
UfsGlobal.Extension.download({
url: listUrls[0].url,
filename: username + (listUrls[0].type === "img" ? ".jpg" : ".mp4"),
});
} else {
let w = window.open("", "", "width=500,height=700");
w.document.write(
listUrls
.map(({ url, type }) =>
type === "video"
? `<video controls src="${url}" style="max-width:300px"></video>`
: type === "img"
? `<img src="${url}" style="max-width:300px" />`
: ""
)
.join("<br/>")
);
}
},
},
};