-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunfollow.js
246 lines (189 loc) · 5.27 KB
/
unfollow.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
Simple script - facebook unfollower/unfriend
(c) FreeAngel - 2021
https://www.youtube.com/channel/UCqRqvw9n7Lrh79x3dRDOkDg
*/
/* you can edit this value ----------------------------------------------------- */
const interval = 1000; // in milliseconds
var wait_delay = 5; // in seconds
const reload_after_unlike = 40; // reload after unfriend > 40
var ignore_names = [];
/* ----------------------------------------------------------------------------- */
const _NO_SECTION_TIMEOUT = 120; // every 120 secs (two minutes) if no item found will reload the page
cur_tick = 0;
no_section = false;
unlike_count = 0; // action / section / account
enable = 0;
total = 0;
var first = true;
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
cur_tick += interval/1000;
if(first){
// if reload executed, get info from background
first = false;
chrome.runtime.sendMessage({
action:"get"
}, function(response){
enable = response.enable;
if(enable){
total = response.total;
} else {
var info = document.getElementById("info_ex");
if(info) {
info.parentNode.removeChild(info);
}
}
var str = response.ignore_list;
ignore_names = str.split(",");
wait_delay = response.interval;
if(wait_delay < 1) { wait_delay = 5;}
});
return;
}
if(!enable) { return; }
show_info();
DoJob();
console.log("Wait ...");
}
}, interval);
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == "set"){
enable = request.enable;
if(enable){
total = 0;
} else {
var info = document.getElementById("info_ex");
if(info) {
info.parentNode.removeChild(info);
}
}
var str = request.ignore_list;
ignore_names = str.split(",");
wait_delay = request.interval;
if(wait_delay < 1) { wait_delay = 5;}
return;
}
});
function DoJob(){
if(cur_tick < wait_delay ) {
info("Wait "+(wait_delay - cur_tick).toString());
return;
}
var cur_url = window.location.href;
if(no_section) {
if (cur_tick >= _NO_SECTION_TIMEOUT) { console.log("reloading page ..."); window.location.href = cur_url; }
return;
}
cur_tick = 0;
if(cur_url.indexOf("facebook.com") === -1) { return; }
if(cur_url.indexOf("/friends") === -1) {
return;
}
if(unlike_count >= reload_after_unlike) { console.log("reloading page ..."); window.location.href = cur_url; }
QuerySection();
}
function QuerySection(){
//bp9cbjyn ue3kfks5 pw54ja7n uo3d90p7 l82x9zwi n1f8r23x rq0escxv j83agx80 bi6gxh9e discj3wi hv4rvrfc ihqw7lf3 dati1w0a gfomwglr
var section = document.querySelectorAll('div.gfomwglr');
if((!section) || (section.length < 1)) {
console.log("Section Not Found !");
no_section = true;
return;
}
var sign = null;
var img = null;
var uname = "";
var lastSection = null;
var found = 0;
for(var i=0; i<section.length; i++){
lastSection = section[i];
img = section[i].getElementsByTagName("img");
if(img === null) { console.log("no img tag found !"); break; }
sign = section[i].getAttribute("signed");
if(sign === "1"){
//console.log("already signed");
continue;
}
section[i].setAttribute("signed",1);
uname = getUser(section[i]);
console.log(uname);
if(isIgnored(uname)){
console.log("ignored");
continue;
}
found++;
var btn = section[i].querySelector('div[aria-label="Friends"]');
if(!btn) { continue; }
unlike_count++;
btn.click();
UnFollow(section[i]);
break;
}
if(lastSection) { lastSection.scrollIntoView(); }
if(found < 1) {
console.log("No Item found");
no_section = true;
}
}
function getUser(sec){
var div = sec.querySelectorAll('span[dir="auto"]');
if(!div) { return ""; }
var s = div[0].textContent;
if(s) { return s.trim(); } else { return ""; }
}
function UnFollow(sec){
var span = document.querySelectorAll('span[dir="auto"]');
var txt = '';
for(var i=0; i<span.length; i++){
txt = span[i].textContent;
if(txt === "Unfriend"){
//console.log("Unfriend clicked !");
//span[i].textContent = "UnfriendX";
span[i].click();
setTimeout(function(){
var div = document.querySelector('div[aria-label="Confirm"]');
if(div) { div.click();}
},500);
total++;
chrome.runtime.sendMessage({
action: "unfriend",
value: 1
});
info('');
break;
}
}
}
function isIgnored(uname){
var b = false;
for(var i=0; i<ignore_names.length; i++){
var s = ignore_names[i].trim();
if(uname === s){
b = true;
break;
}
}
return b;
}
function show_info(){
var info = document.getElementById("info_ex");
if(!info) {
info = document.createElement('div');
info.style.cssText = "position: fixed; bottom: 0; width:100%; z-index: 999;background-color: #F5FACA; border-style: solid; border-width: 1px; margins: 5px; paddingLeft: 10px; paddingRight: 10px;";
info.innerHTML = "<center><h3 id='status_ex'>active</h3></center>";
info.id = "info_ex";
document.body.appendChild(info);
console.log("info_ex created");
}
}
function info(txt){
var info = document.getElementById("status_ex");
if(!info) { return; }
if(txt != ''){
info.textContent = "Unfriend : "+total+", "+txt;
} else {
info.textContent = "Unfriend: "+total;
}
}