-
Notifications
You must be signed in to change notification settings - Fork 1
/
facebook-timeline-cleaner.user.js
441 lines (372 loc) · 14.8 KB
/
facebook-timeline-cleaner.user.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
// ==UserScript==
// @name Facebook Cleaner
// @url Based on http://userscripts.org/scripts/show/125120
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
// @require http://code.jquery.com/jquery-1.7.1.min.js
// ==/UserScript==
/*
*No warranty. Use with your own risk.
*V0.5
*/
/*
* Some Global Variables for User Edit
*/
var expandCount = 3;
var deleteCount = 3;
var limit = false;
/*
* This is the Debug Level for the firebug console output. It goes up to 5
*/
var debug = 2;
/*
* If this option is true, nothing will be really deleted.
* So you can test something without losing your timeline....
*/
var just_test = false;
/*
* Internal Variables. Do not edit!
*/
var deletedMap = {};
var triggeredMap = {};
var post_form_id = 1; // Security constant generated by Facebook, no longer used, so this is an arbitrary value
var fb_dtsg = null; // Security constant generated by Facebook
var delete_time_before = null;
var iamstillontimeline = false;
var start = false;
var lastselected = null;
var insert_button = false;
var deleted = 0;
var hided=0;
var only_hide = false;
/*
* * * * *
*/
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
/*
* This function scroll down on the website and load any entries.
*/
var expandMoreActivity = function() {
var links = $('a[onclick]'); //
for ( var i = 0; i < links.length; ++i) {
//Umg this works only in german or english :
if ((links[i].innerHTML === "More Activity") || (links[i].innerHTML === "Weitere Aktivitäten")) {
if (limit) {
expandCount -= 1;
}
links[i].click();
}
}
if (!limit || (limit && expandCount >= 0)) {
if (iamstillontimeline == true) {
setTimeout(expandMoreActivity, 1000);
scrollTo(0, 1000000000); //Scroll Down!
}
}
logging('Expand', 2);
}
var getConstantParameters = function () {
logging('getConstantParameters() starting...',2);
if ( post_form_id != null && fb_dtsg !== null ) {
return true;
} else {
if ( post_form_id === null ) {
logging('Searching for post_form_id constant...',2);
$('input[name="post_form_id"]').each(function(){
post_form_id = $(this).attr("value");
logging('Found post_form_id constant',2);
});
}
if ( fb_dtsg === null ) {
logging('Searching for fb_dtsg constant...',2);
$('input[name="fb_dtsg"]').each(function(){
fb_dtsg = $(this).attr("value");
logging('Found fb_dtsg constant = ' + fb_dtsg,2);
});
}
return (post_form_id != null && fb_dtsg !== null);
}
}
var createDeleteRequests = function () {
//logging('createDeleteRequests() starting...',2);
if ( getConstantParameters() ) {
logging('Begin.',2);
check_for_timeline(); // Mh does im on the right site?
//Sometimes Facebook change here some shit...
if($('ul[class="uiList mbm uiStream timelineAllActivityStream fbProfileStream translateParent"]').size()==0){
if(iamstillontimeline==true){
alert("ERROR: Maybe Facebook changed its design... \n please take a look for a newer version of this Script...");
}
}
$('ul[class="uiList mbm uiStream timelineAllActivityStream fbProfileStream translateParent"]').each( function() {
var year = $(this).attr("id").split("all_activity_stream_")[1];
$(this).find('a[ajaxify]').each(function () {
var remove = true;
var ajaxify = parseUri("http://facebook.com" + $(this).attr("ajaxify"));
var keys = ['profile_id', 'story_fbid', 'story_fbid', 'story_row_time', 'story_dom_id'];
for ( var i = 0; i < keys.length; ++i) {
if (ajaxify.queryKey[keys[i]] === undefined) {
remove = false;
}
}
//console.log("The Timestamp is:",ajaxify.queryKey['story_row_time']);
//logging("Ajax Datei:"+ajaxify.file,2);
/*
Hier wird überprüft, ob die Post ggf. ein bestimmtes alter haben sollen.
Definiert über delete_time_before in sec vor now
*/
now = Math.round((new Date()).getTime() / 1000);
if(delete_time_before!==false){
if(ajaxify.file !== "show_story_options.php"){
if((now-ajaxify.queryKey['story_row_time']) <delete_time_before){
if ( remove && deletedMap[ajaxify.queryKey['story_fbid']] === undefined ) {
deletedMap[ajaxify.queryKey['story_fbid']] = false;
console.log("This Entry is too young! NEXT! ID:",ajaxify.queryKey['story_fbid']);
console.log("Target time: >",delete_time_before," Ist Zeit:",now-ajaxify.queryKey['story_row_time']);
}
}
}
}
if ( ajaxify.file === "show_story_options.php") {
if ( triggeredMap[ajaxify.queryKey['story_fbid']] === undefined ) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
$(this).context.dispatchEvent(evt);
triggeredMap[ajaxify.queryKey['story_fbid']] = true;
}
} else if ( (ajaxify.file === "take_action_on_story.php") && (only_hide === false)){
// TODO: Apply same changes here as below for story_visibility.php, or preferably refactor - haven't used this option
if ( remove && deletedMap[ajaxify.queryKey['story_fbid']] === undefined ) {
deletedMap[ajaxify.queryKey['story_fbid']] = false;
logging("Loesche die ID:"+ajaxify.queryKey['story_fbid'],1);
deleted=deleted+1; //Count Up for stats...
var data = {
'nctr[_mod]' : "pagelet_all_activity_" + year,
//'post_form_id' : post_form_id,
'fb_dtsg' : fb_dtsg,
'lsd' : "",
'post_form_id_source' : "AsyncRequest",
'confirmed' : "1",
'ban_user' : "0"
};
for ( var key in ajaxify.queryKey ) {
data[key] = ajaxify.queryKey[key];
}
if(just_test==false) {
$.ajax({
type : "POST",
url : "http://www.facebook.com/ajax/timeline/take_action_on_story.php?__a=1",
data : data,
success: function() {
$(this).remove() ;
}
});
}
}
} else if ( ajaxify.file === "story_visibility.php" ) {
/*
As of 27/8/2012, the submission should be like:
GET: /ajax/timeline/story_visibility.php
POST:
profile_id:5906453
story_fbid:0100338657365090
story_row_time:345919668
activity_log:1
story_dom_id:u23ask_6
__user:5906453
__a:1
action:hide
nctr[_mod]:pagelet_all_activity_2012_8
fb_dtsg:AQCfjjgM
phstamp:65816710210610610377201
The URL in the link is like:
/ajax/timeline/story_visibility.php?profile_id=5906453&story_fbid=0100338657365090&story_row_time=345919668&activity_log=1&story_dom_id=u2wonw_8&__user=5906453&__a=1&action=hide
*/
if ( remove && deletedMap[ajaxify.queryKey['story_fbid']] === undefined ) {
deletedMap[ajaxify.queryKey['story_fbid']] = false;
console.log ("Change Visibility to hide for ID:",ajaxify.queryKey['story_fbid'] );
hided=hided+1;
var data = {
'nctr[_mod]' : "pagelet_all_activity_" + year,
'fb_dtsg' : fb_dtsg,
'action' : "hide",
};
for ( var key in ajaxify.queryKey ) {
if(key!='action') {
data[key] = ajaxify.queryKey[key];
}
}
// Generate the query string
var qs = buildUrl(data);
// Add the phstamp value
data['phstamp'] = generatePhstamp(qs, fb_dtsg);
logging('phstamp = ' + data['phstamp'] + ' and values = ' + qs, 2);
if(just_test==false) {
$.ajax({
type : "POST",
url : "http://www.facebook.com/ajax/timeline/story_visibility.php",
data : data,
success: function() {
$(this).remove();
}
});
}
}
}
});
});
}
if (iamstillontimeline == true) {
setTimeout(createDeleteRequests, 1000);
}
}
// Compile the query string: http://stackoverflow.com/questions/316781/how-to-build-query-string-with-javascript
function buildUrl(parameters){
var qs = "";
for(var key in parameters) {
var value = parameters[key];
qs += key + "=" + value + "&";
}
if (qs.length > 0){
qs = qs.substring(0, qs.length-1); //chop off last "&"
}
return qs;
}
// Function to generate the Phstamp value: http://pastebin.com/VJAhUw30
function generatePhstamp(qs, dtsg) {
var input_len = qs.length;
numeric_csrf_value='';
for(var ii=0;ii<dtsg.length;ii++) {
numeric_csrf_value+=dtsg.charCodeAt(ii);
}
return '1' + numeric_csrf_value + input_len;
}
/*
* This function check your URL. If your url contains "$suchstring", the script will load.
*/
function check_for_timeline() {
var suchstring = /(allactivity)/g; //REGEX for the URL
var searchresult = suchstring.test($(location).attr('href'));
if (searchresult != false) {
iamstillontimeline = true; //You are on the right site!
}
else {
if ((iamstillontimeline == true) && (start == true)) {
// Ugh it seems the user change the side...
alert('Abort!');
start = false;
}
iamstillontimeline = false;
insert_button = false;
}
}
/*
* A Logging Function with global debug level.
*/
function logging(text, level) {
if (debug >= level) {
console.log(text);
}
}
/*
* This Function updates the status counter
*/
function update_status() {
logging('Update Statusbar', 3);
document.getElementById("delete").innerHTML = 'Deleted:' + deleted;
document.getElementById("Hided").innerHTML = 'Hide:' + hided;
}
/*
* Insert the GUI Button
*/
function add_button(){
insert_button=true;
$('span[class="uiButtonGroup fbStickyHeaderBreadcrumb uiButtonGroupOverlay"]').append('<span class="uiButtonGroupItem selectorItem"><div class="uiSelector inlineBlock sectionMenu uiSelectorNormal uiSelectorDynamicLabel"><div class="wrap "><button class="hideToggler"></button><a rel="toggle" data-length="30" aria-haspopup="1" href="#" role="button" class="uiSelectorButton uiButton uiButtonOverlay "><span class="uiButtonText" style="background-color: red;">Privacy Extension</span></a><div class="uiSelectorMenuWrapper uiToggleFlyout"><div class="uiMenu uiSelectorMenu" role="menu"><ul class="uiMenuInner"><li class="uiMenuItem uiMenuItemRadio uiSelectorOption " data-key="year_2012" data-label="Hide everything on Timeline" ><a href="#" rel="ignore" class="itemAnchor" tabindex="0" aria-checked="true"><span class="itemLabel fsm">Hide everything on Timeline older than 90 days</span></a></li><li class="uiMenuItem uiMenuItemRadio uiSelectorOption" data-key="year_2011" data-label="Delete everything"><a href="#" rel="ignore" class="itemAnchor" tabindex="0" aria-checked="false"><span class="itemLabel fsm">Delete everything</span></a></li><li class="uiMenuItem uiMenuItemRadio uiSelectorOption " data-key="Hide everything on Timeline" data-label="Hide everything on Timeline"><a href="#" rel="ignore" class="itemAnchor" tabindex="0" aria-checked="false"><span class="itemLabel fsm">Hide everything on Timeline</span></a></li><li class="uiMenuItem uiMenuItemRadio uiSelectorOption" data-key="year_2009" data-label="Delete everything older than 90 Days"><a href="#" rel="ignore" class="itemAnchor" tabindex="0" aria-checked="false"><span class="itemLabel fsm">Delete everything older than 90 Days</span></a></li></ul></div></div><button class="hideToggler"></button></div><select id="selectvalue"><option value=""></option><option value="year_2012">Hide everything on Timeline older than 90 days</option><option value="year_2011">Delete everything</option><option value="year_201x">Hide everything on Timeline</option><option value="year_2009">Delete things older than 90 Days</option><option value="year_2010" >Hide everything on Timeline older than 90 Days</option></select></div></span>');
}
/*
* This is the Main Function. It checks if you are on the activies log or not. :D
*/
function main()
{
check_for_timeline(); //Get my location.
if (iamstillontimeline == true) {
if (insert_button == false) {
console.log('Adding button...');
add_button();
}
if (start == true) {
update_status();
}
if (just_test != false) {
logging("This is only a test! Nothing will be really deleted!",1);
}
// Check that the button is really inserted...
if(document.getElementById("selectvalue")) {
var selected=document.getElementById("selectvalue").options[document.getElementById("selectvalue").selectedIndex].text;
if (start == false) {
logging('Waiting for start signal', 1);
if ((lastselected != selected) && (selected != "")) {
switch (selected) {
case "Hide everything on Timeline":
var text = 'WARNING: Are you sure you want hide EVERYTHING on your Timeline? Only you will be able to see the old entries!';
only_hide = true;
delete_time_before = false;
break;
case "Delete everything":
var text = 'WARNING: Are you sure to delete EVERYTHING on your Timeline?!';
only_hide = false;
delete_time_before = false;
break;
case "Hide everything on Timeline older than 90 days":
var text = 'WARNING: Are you sure you want hide all entries that are older than 90 Days?';
only_hide = true;
delete_time_before = 60 * 60 * 24 * 90;
break;
case "Delete things older than 90 Days":
var text = 'WARNING: Are you sure you want DELETE all entries that are older than 90 Days?';
only_hide = false;
delete_time_before = 60 * 60 * 24 * 90;
break;
}
lastselected = selected;
if (confirm(text)) {
$('span[class="uiButtonGroup fbStickyHeaderBreadcrumb uiButtonGroupOverlay"]').append('<div id="delete"> Deleted: 0</div><div id="Hided"> Hide: 0</div>');
start=true;
console.log("Start with ",selected);
createDeleteRequests();
expandMoreActivity();
console.log ( "ajaxify:", $('*[ajaxify]').attr("ajaxify") );
}
}
}
} else {
//dafuq?! Button was not found... so insert it!!!
add_button();
}
}
setTimeout(main, 2000); // Start itself in 2 seconds again.
}
setTimeout(main, 4000);