-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
tag_by_ID.js
202 lines (190 loc) · 4.91 KB
/
tag_by_ID.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
javascript:
var currentLocation = window.location.href;
var string_url = currentLocation.split("/");
function fail(){
alert("Bạn phải ở đúng trang đã");
}
function failMobile(){
alert("Không hỗ trợ cho điện thoại");
}
function failPhotos(){
alert("Không tag được trên ảnh");
}
function failUID(){
alert("Nhập sai số ID");
}
function redirect(id_post) {
fail();
window.location.href = "http://fb.com/"+id_post;
}
function getGroup(){
try{
var div = document.getElementsByClassName("coverWrap");
var id = div[0].dataset.referrerid;
if(id!="null") return 1;
else return 0;
}
catch (e){
return 0;
}
}
function getAllUrlParams() {
var queryString = currentLocation ? currentLocation.split('?')[1] : window.location.search.slice(1);
var obj = {};
if (queryString) {
queryString = queryString.split('#')[0];
var arr = queryString.split('&');
for (var i=0; i<arr.length; i++) {
var a = arr[i].split('=');
var paramNum = undefined;
var paramName = a[0].replace(/\[\d*\]/, function(v) {
paramNum = v.slice(1,-1);
return '';
});
var paramValue = typeof(a[1])==='undefined' ? true : a[1];
paramName = paramName.toLowerCase();
if (obj[paramName]) {
if (typeof obj[paramName] === 'string') {
obj[paramName] = [obj[paramName]];
}
if (typeof paramNum === 'undefined') {
obj[paramName].push(paramValue);
}
else {
obj[paramName][paramNum] = paramValue;
}
}
else {
obj[paramName] = paramValue;
}
}
}
return obj;
}
function getPost(){
try{
if(currentLocation.indexOf("m.facebook") !== -1){
failMobile();
return 1;
}
else if(currentLocation.indexOf("/permalink/") !== -1){
var id = string_url[6];
return id;
}
else if(currentLocation.indexOf("videos") !== -1){
var id = string_url[string_url.length-2];
var check = getGroup();
if(check!=0){
redirect(id);
return 1;
}
else{
return id;
}
}
else if(currentLocation.indexOf("photo") !== -1){
var check = getGroup();
if(check!=0){
var set = getAllUrlParams().set;
var string = set.split(".");
var id = string[1];
redirect(id);
return 1;
}
else{
failPhotos();
return 1;
}
}
else if(currentLocation.indexOf("posts") !== -1){
var set = string_url[string_url.length-1];
var string = set.split("?");
var id = string[0];
return id;
}
return 0;
}
catch (e){
return 0;
}
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
return typeof obj;
} : function(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var id_post = getPost();
if(id_post!=0 && id_post!=1 && isNumber(id_post)==true){
var uid = prompt('Nhập số ID Facebook người muốn tag');
if(isNumber(uid)){
var text = prompt('Nhập nội dung muốn nhắn');
addCmt();
}
else{
failUID();
}
}
else if(id_post!=1){
fail();
}
function addCmt() {
request('https://www.facebook.com/ufi/add/comment/?dpr=1', {
ft_ent_identifier: id_post,
comment_text: '@[' + uid + ':0] '+text,
av: getUserID(),
__user: getUserID(),
__a: 1,
fb_dtsg: getUserToken(),
source: 2,
client_id: '1489983090155:3363757627',
session_id: '84d81e4'
});
}
function request(url, data) {
fetch(url, {
method: 'POST',
credentials: 'include',
body: JSONtoFormData(data)
}).then(function(response) {
if(response.ok) {
window.scrollTo(0,document.body.scrollHeight);
}
});
}
function JSONtoFormData(json) {
if ((typeof json === 'undefined' ? 'undefined' : _typeof(json)) !== 'object') {
if (typeof json === 'string') {
try {
json = JSON.parse(json);
} catch (e) {
return false;
}
} else {
return false;
}
}
var formData = new FormData();
Object.keys(json).map(function(key) {
formData.append(key, json[key]);
});
return formData;
}
function getUserID() {
if (typeof require !== 'function') return null;
try {
return require('CurrentUserInitialData').USER_ID || document.cookie.match(/c_user=([0-9]+)/)[1];
} catch (e) {
return null;
}
}
function getUserToken() {
if (typeof require !== 'function') return null;
try {
return require('DTSGInitialData').token || document.querySelector('[name="fb_dtsg"]').value;
} catch (e) {
return null;
}
}