-
Notifications
You must be signed in to change notification settings - Fork 0
/
newscriptbis.js
156 lines (124 loc) · 2.63 KB
/
newscriptbis.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
// ==UserScript==
// @name Facebook_cleaner
// @namespace Facebook_cleaner
// @description cleans facebook timeline
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
// @require http://code.jquery.com/jquery-1.7.1.min.js
// @version 1
// @grant none
// ==/UserScript==
/*
** Variables :
*/
// Selectors :
var button_location = 'div[class="_2o3t fixed_elem"]';
var button_classes = '_42ft _4jy0 _11b _4jy3 _4jy1 selected _51sy';
// Flags :
var buttons_added = false;
var url_observer_launched = false;
/*
** Basic functions :
*/
function check_timeline()
{
if (/(allactivity)/g.test($(location).attr('href'))){
return true;
}
return false;
}
function add_button(text, code){
// Creating the button.
var button = document.createElement('button');
// Creating the text.
var button_text = document.createTextNode(text);
// Getting the target element.
var location = $(button_location);
// Setting button classes.
button.className = button_classes;
// Making the button a submit button.
button.setAttribute('type', 'submit');
// Binding the code to the 'click' button event.
button.addEventListener('click', code);
// Make the button append the text node.
button.appendChild(button_text);
// make the location append the button.
location.append(button);
}
function reset(){
return true;
}
/*
** Evolved functions :
*/
function add_all_button(){
var text = 'Delete ALL this shit!';
var fn = function(){
alert("delete all!");
};
add_button(text, fn);
}
function add_one_button(){
var text = 'Delete ONE of this shit!';
var fn = function(){
alert('Delete one');
};
add_button(text, fn);
}
function add_buttons(){
buttons_added = true;
add_all_button();
add_one_button();
}
/*
** Event handling functions :
*/
function handling_url_change(mutations){
mutations.forEach(function (mutation){
if (check_timeline()){
if (!buttons_added){
var element = $(document).find(button_location);
if (element && element.length > 0){
add_buttons();
}
}
}else{
reset();
}
};
}
/*
** Mutation observers :
*/
var url_mutation_observer(handling_url_change);
/*
** Mutation observer starting functions :
*/
var dictionnary = {
childList: true,
subtree: true,
attributes: false,
characterData: false
};
// Must start url_mutation_observer.
function start_url_observer(){
url_mutation_observer.observe(document, dictionnary);
url_observer_launched = true;
}
/*
** Launching :
*/
function launch()
{
if (check_timeline()){
if (!buttons_added){
add_buttons();
}
}else{
reset();
}
if (!url_observer_launched){
start_url_observer();
}
}
launch();