-
Notifications
You must be signed in to change notification settings - Fork 0
/
m5stop.js
328 lines (270 loc) · 7.84 KB
/
m5stop.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
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
//definisco il blocco da schiantare in overlay
blocker = '<div class="m5sblocker">'+
'<div class="m5sblocker-profile-fader"></div>'+
'<div class="m5sblocker-inner">'+
'<div class="m5sblocker-txt">'+
'<div class="m5sblocker-disclaimer fwb">ATTENZIONE, può contenere materiale grillesco</div>'+
'<div class="m5sblocker-ctas">'+
'<span class="m5sblocker-cta quote _42ft _4jy0 _4jy3 _517h">Sostituisci con perla random</span>'+
'<span class="m5sblocker-close _42ft _4jy0 _4jy3 _517h">Mi arrischio.</span>'+
'</div>'+
'</div>'+
'</div>'+
'</div>';
//definisco le chiavi di ricerca
keywords = [
/\b(beppe )?(grillo)\b/gi,
/\b(andrea )?(scanzi)\b/gi,
/\b(alessandro )?(di battista)\b/gi,
///\b(5 )?(stelle)\b/gi,
/\b(m5s)\b/gi,
/\b(renzie)\b/gi,
/\b(5 stelle)\b/gi,
/\b(5stelle)\b/gi,
/\b(cinque stelle)\b/gi,
/\b(cinquestelle)\b/gi,
/\b(casaleggio)\b/gi,
/\b(luigi di maio)\b/gi,
/\b(giulia sarti)\b/gi,
/\b(vito crimi)\b/gi,
/\b(mattia calise)\b/gi,
/\b(paola taverna)\b/gi
// /\b(vinciamonoi)\b/gi,
// /\b(pidimenoelle)\b/gi
];
var newPost =
'<div class="topBorder"></div>'+
'<div class="m5stopped">'+
'<div role="article">'+
'<div class="userContentWrapper m5sBlockDone"></div>'+
'</div>'+
'</div>'+
'<div class="bottomBorder"></div>';
//var item1 = $( "li.item-1" )[ 0 ];
//$( "li.item-ii" ).find( item1 ).css( "background-color", "red" );
$.fn.randomQuote = function() {
var element = this;
// userInfo = $('.clearfix._5x46');
// switch(true) {
// case ($('body').hasClass('home')):
// userInfo = $('.clearfix._5x46');
// break;
// case ($('body').hasClass('timelineLayout')):
// userInfo = $('.mbs.pbs._1_m');
// break;
// case ($('body').hasClass('timelineLayout') && $('body').hasClass('pagesTimelineLayout')):
// userInfo = $('.clearfix._5x46');
// break;
// case ($('body').hasClass('pagesTimelineLayout')):
// userInfo = $('.clearfix._5x46');
// }
userInfo = $('.clearfix._5x46');
var userInfo = this.find($(userInfo));
element.wrapInner('<div class="temp_controller"></div>');
var blocker = element.find('.m5sblocker');
var old = element.find('.temp_controller');
blocker.appendTo(element);
old.height(old.height()).contents().remove();
blocker.animate({
'opacity' :0
},150,function () {
blocker.remove()
})
function successo(results) {
var curHeight = old.height();
old.css('height', 'auto');
old.append(newPost).css({'opacity' : '0'}).find('.m5stopped').prepend(userInfo);
//var authLink = results.titles.replace(' ', '+')
var str = '<span class="m5sblock-quote">'+results.quote+'</span><br><br>('+results.titles+')';
var html = $.parseHTML( str );
element.find('.userContentWrapper').append( html );
var autoHeight = old.height();
old.height(curHeight).animate({
'opacity' : '1',
'height' : autoHeight
}, 150);
//se è vuota recuperane un altra
if (old.find('.m5sblock-quote').text() == 'undefined') {
console.log('quote undefined, restart...')
element.randomQuote()
}
}
function test(results) {
console.log(results.titles)
console.log('cit: '+results.quote)
console.log('------------')
}
function testError(errore) {
console.error('Errore: '+errore);
}
function errore(errore) {
console.error('Errore: '+errore);
console.log('restart della funzione...')
go()
}
authors = [
"Karl Popper",
"Karl Marx",
"Antonio Gramsci",
"Thomas Hobbes",
"John Locke",
"Immanuel Kant",
"Friedrich Nietzsche",
"Marcel Proust",
"Bertolt Brecht",
"Platone",
"Albert Einstein",
"Schopenhauer",
"Aristotele",
"Sigmund Freud",
"Blaise Pascal",
"Sartre",
"Hegel",
"Montaigne",
"John Maynard Keynes",
"Wittgenstein",
"Kierkegaard",
"Isaac Newton",
"Martin Heidegger",
"Carl Gustav Jung",
"Michel Foucault",
"Simone Weil",
"Cesare Beccaria",
"Palmiro Togliatti",
"Enrico Berlinguer",
"Giacomo Matteotti",
"Filippo Turati",
"Giorgio Amendola",
"Sandro Pertini",
"Tommaso Moro",
"Robert Owen",
"Henri de Saint-Simon",
"Charles Fourier",
"Pierre-Joseph Proudhon",
"Alexander Herzen",
"John Stuart Mill",
"Friedrich Engels",
"Michail Bakunin",
"Léon Blum",
"Benedetto Croce",
//risorgimento
"Adelaide Cairoli",
"Amatore Sciesa",
"Beppe Fenoglio",
"Carlo Cattaneo",
"Carlo Pisacane",
"Enrico Toti",
"Felice Orsini",
"Francesco Crispi",
"Gabriele Rossetti",
"Giovanni Berchet",
"Giuseppe Mazzini",
"Goffredo Mameli",
"Guglielmo Pepe",
"Luigi Settembrini",
"Madame de Staël",
"Massimo d'Azeglio",
"Pietro Colletta",
"Silvio Pellico",
"Stendhal",
"Tommaso Campanella",
"Ugo Foscolo",
"Vincenzo Cuoco",
"Vincenzo Gioberti",
"Vittorio Alfieri"
// "Luigi Einaudi",
// "Alcide De Gasperi"
];
function go() {
var author = authors[Math.floor(Math.random()*authors.length)];
console.log(author)
WikiquoteApi.getRandomQuote(author, successo, errore );
}
go()
//testa l'array di autori
// for ( var i = 0; i < authors.length; i = i + 1 ) {
// //console.log( authors[ i ] );
// WikiquoteApi.getRandomQuote(authors[ i ], test, testError );
// }
};
$.fn.block = function(container) {
var container = container;
var current = this;
if (
!this.hasClass('m5sblocked')
&&
!this.parents('.m5sblocked').length > 0
) {
this.addClass('m5sblocked').prepend(blocker);
this.find('.m5sblocker-close').click(function () {
$(this).closest('div.m5sblocker').animate({
'opacity' :0
},150,function () {
$(this).closest('div.m5sblocker').remove()
})
})
this.find('.m5sblocker-cta.quote').click(function () {
//qui chiamo la citazione
current.randomQuote()
})
}
};
var observer = new MutationObserver(function (mutations) {
var wallItem = $('.userContentWrapper');
var container = wallItem.parent();
switch(true) {
case ($('body').hasClass('home')):
var wallItem = $('.userContentWrapper');
var container = $('.userContentWrapper');
break;
case ($('body').hasClass('timelineLayout')):
//console.log('timelineLayout')
var wallItem = $('.userContentWrapper');
var container = wallItem.parent();
//var container = $('.userContentWrapper');
var container = $('.fbTimelineUnit, ._4-u2.mbm');
break;
case ($('body').hasClass('timelineLayout') && $('body').hasClass('pagesTimelineLayout')):
//console.log('pagesTimelineLayout')
var wallItem = $('.timelineUnitContainer');
var container = $('.timelineUnitContainer');
break;
case ($('body').hasClass('pagesTimelineLayout')):
var wallItem = $('.userContentWrapper');
var container = wallItem.parent();
}
wallItem.each(function () {
//console.log('--')
var element = $(this);
//console.log(element);
$.each( keywords, function( key, value ) {
//console.log($this);
var rSearchTerm = new RegExp(value);
//console.log($this)
element.contents().filter(function(value) {
//element.css({'background':'red'})
return (rSearchTerm).test($(this).text()); // return every match as jQuery obj
}).closest(container).block($(container)); // <--example, do your stuff here.
});
})
});
// select the target node
var target = document.querySelector('#globalContainer');
// create an observer instance
//var observer = new MutationObserver(function(mutations) {
// mutations.forEach(function(mutation) {
// console.log(mutation.type);
// });
//});
// configuration of the observer:
var config = {
childList: true,
attributes: false,
characterData: true,
subtree: true
};
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
//observer.disconnect();