-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscript.user.js
375 lines (327 loc) · 11.4 KB
/
script.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
// ==UserScript==
// @name anti AEDE
// @namespace http://www.meneame.net/
// @version 2.0.0.1
// @description marcar en rojo
// @include *
// @updateURL https://raw.github.com/hacknlove/anti-AEDE/master/script.user.js
// @copyright Antonio Fernández Porrúa. Pau Capó. Licencia GPL
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @require http://hacknlove.github.io/anti-AEDE/javascripts/jquery.minicolors.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
/* jshint -W030 */ // para poder usar a && b como atajo para if(a) b
$(function () {
var contador=1 // Contador de las comprobaciones de los links
var checklinksinterval; //Variable global que guarda el numero del setInterval() para poder pararlo.
var parseList = function(list){
return list.split('\n').filter(function(domain){
return domain.length!==0;
});
},
generateRegExp = function(list){
return list.map(function(domain){
domain = domain.replace(/\./g,'\\.');
return new RegExp('(^|(^[^/]*\\.)|(^http(s?)://)|(^http(s?)://)[^/]*\\.)'+domain+'(/|$)');
});
},
main = function(regexps){
firsTime();
checkForLinks(regexps);
checklinksinterval = setInterval(function() {
checkForLinks(regexps);
if(contador++ >= GM_getValue('number_iterations')) {
clearInterval(checklinksinterval);
}
}, GM_getValue('time2checklinks'));
},
checkForLinks = function (regexps) {
switch(domain){
case 'meneame.net':
GM_getValue('meneame') && meneame(regexps);
break;
case 'twitter.com':
GM_getValue('twitter') && twitter(regexps);
break;
case 'facebook.com':
GM_getValue('facebook') && facebook(regexps);
break;
case 'imgur.com':
break;
default:
GM_getValue('others') && others(regexps);
break;
}
},
firsTime = function () {
switch(domain){
case 'meneame.net':
GM_getValue('meneame') && firsTimeMeneame();
break;
//~ case 'twitter.com':
//~ GM_getValue('twitter') && firsTimeTwitter();
//~ break;
//~ case 'facebook.com':
//~ GM_getValue('facebook') && firsTimeFacebook();
//~ break;
//~ case 'imgur.com':
//~ break;
//~ default:
//~ GM_getValue('others') && firsTimeOthers();
//~ break;
}
},
firsTimeMeneame = function(){
$('input#url').bind('input', function () {
var that = $(this);
if(isAEDE(that.val())){
that.css('border', '2px solid red');
}else{
that.css('border', '1px solid #ddd');
}
});
},
meneame = function (regexps) {
$('span.showmytitle').not('[data-anti-aede-checked]').each(function (i) {
var title = this.title
element = $(this).parents('.news-body');
if(element.length){
//console.log('showmy');
preCheckElement(regexps, element, title, i);
}
}).attr('data-anti-aede-checked', '');
$('.comment-body>a').not('[data-anti-aede-checked]').each(function(i){
var title = $(this).attr('href'),
element = $(this).parent();
preCheckElement(regexps, element, title, i);
}).attr('data-anti-aede-checked', '');
},
twitter = function (regexps) {
// Twitter by @Hanxxs http://pastebin.com/f04tPcsG
$('a.twitter-timeline-link').not('[data-anti-aede-checked]').each(function (i) {
var title = this.title,
element = $(this).parents('.stream-item');
preCheckElement(regexps, element, title, i);
}).attr('data-anti-aede-checked', '');
},
facebook = function (regexps) {
// Facebook by @paucapo
$('div.fsm').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).text(),
element = $(this).parents('a.shareLink');
preCheckElement(regexps, element, title, i, {
border: '3px solid ' + GM_getValue('background')
});
}).addClass('aede-on');
$('.userContent a').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).text(),
element = $(this);
preCheckElement(regexps, element, title, i, {
border: '3px solid ' + GM_getValue('background')
});
}).addClass('aede-on');
$('div.userContentWrapper div.fcg').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).text(),
element = $(this).parents('div.mvm');
preCheckElement(regexps, element, title, i, {
display: 'block',
});
}).attr('data-anti-aede-checked', '');
$('div.storyInnerWrapper span.caption').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).text(),
element = $(this).parents('div.shareRedesignContainer');
preCheckElement(regexps, element, title, i);
}).attr('data-anti-aede-checked', '');
},
google = function (regexps) {
// Google by @paucapo
$('a').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).attr('href'),
element = $(this).parents('li.g');
preCheckElement(regexps, element, title, i);
}).attr('data-anti-aede-checked', '');
},
others = function (regexps) {
// Others by @paucapo
$('a').not('[data-anti-aede-checked]').each(function (i) {
var title = $(this).attr('href') + ' ' + $(this).text(),
element = $(this);
preCheckElement(regexps, element, title, i);
}).attr('data-anti-aede-checked', '');
},
preCheckElement = function (regexps, element, url, i, extraCss) {
if(url === undefined){
return;
}
setTimeout(function () {
checkElement(regexps, element, url, extraCss);
}, i * 20);
},
checkElement = function (regexps, element, url, extraCss) {
css = {
'background-color': GM_getValue('background'),
'background-image': 'linear-gradient(0deg, '+GM_getValue('background_gradient')+','+GM_getValue('background')+')',
'border-radius': GM_getValue('background_radius')+'px',
};
if (typeof extraCss != 'undefined') {
$.extend(css, extraCss);
}
if (checkUrl(regexps, url)) {
element
.css(css)
.on('mouseenter', showTooltip).on('mouseleave', hideTooltip);
}
},
showTooltip = function () {
if(!tooltip){
tooltip = $('<span id="aede-tooltip" style="position: absolute;background:' + GM_getValue('tooltip_background') + ';color:' + GM_getValue('tooltip_text') + ';padding:5px;border-radius:4px;z-index:100000">AEDE alert!</span>');
$('body').append(tooltip);
$(document).on('mousemove', tooltipMove);
}
},
hideTooltip = function () {
if(tooltip){
tooltip.remove();
tooltip = false;
$(document).off('mousemove', tooltipMove);
}
},
tooltipMove = function(event){
tooltip.css('top', (event.pageY + 10) + 'px').css('left', (event.pageX + 10) + 'px');
},
checkUrl = function (regexps, url) {
if(Array.prototype.some){
return regexps.some(function(reg){
return reg.test(url);
});
}
},
domain = document.domain.match(/[^\.]*\.[^\.]*$/)[0],
defaults_general = {
url_list: 'http://pykiss.github.io/anti-AEDE/domains.list',
background: '#ffe9e9',
background_gradient: '#ffe9e9',
background_radius: '5',
tooltip_background: '#d04544',
tooltip_text: '#fff',
number_iterations: '10',
time2checklinks: '2000',
},
defaults_modules = {
meneame: true,
twitter: true,
facebook: true,
google: false,
others: true,
},
labels = {
url_list: 'url de la lista de dominios:',
background: 'Color de fondo (empieza por)',
background_gradient: 'Color de fondo (termina en)',
background_radius: 'Redondear los cantos (píxels)',
tooltip_background: 'Color de fondo del tooltip',
tooltip_text: 'Color del texto del tooltip',
meneame: 'Menéame',
twitter: 'Twitter',
facebook: 'Facebook',
google: 'Google (sólo funciona en google.es, se tiene que solucionar)',
others: 'Todas las páginas',
number_iterations: 'Nº comprobaciones',
time2checklinks: 'Tiempo entre comprobaciones(en ms)',
},
general_types = {
background: 'color',
background_gradient: 'color',
background_radius: 'number',
tooltip_background: 'color',
tooltip_text: 'color',
number_iterations: 'number',
time2checklinks: 'number',
},
tooltip = false,
aedeConfig = function () {
$('#aede_config').remove();
var config = '<div id="aede_config">';
config += '<h1>Configuración</h1>';
config += '<h2>General</h2>';
$.each(defaults_general, function (key, value) {
config += '<p><label for="aede_' + key + '">' + labels[key] + ':</label> <input type="text" id="aede_' + key + '" value="' + GM_getValue(key) + '" class="'+general_types[key]+'"></p>';
});
config += '<h2>Módulos</h2>';
config += '<ul>';
$.each(defaults_modules, function (key, value) {
config += '<li><input type="checkbox" id="aede_' + key + '" ' + (GM_getValue(key) === true ? 'checked' : '') + '> <label for="aede_' + key + '">' + labels[key] + '</label></li>';
});
config += '</ul>';
config += '<p><input type="button" id="aede_save" value="Guardar"> <input type="button" id="aede_reset" value="Reset"></p>';
config += '<style type="text/css">#aede_config{border:1px solid #eee;padding:0 20px;background:#f9f9f9;}#aede_config p label{width:50%;display:block;float:left;}#aede_config ul{list-style:none;}</style>';
config += '</div>';
$('#main_content').append(config);
$('input.color').each( function() {
$(this).minicolors({
control: 'hue',
defaultValue: '',
inline: false,
letterCase: 'lowercase',
opacity: false,
position: 'bottom left',
theme: 'default'
});
});
$('#aede_reset').on('click', function () {
resetConfig();
aedeConfig();
resultConfig('¡Configuración a valores por defecto!');
});
$('#aede_save').on('click', function () {
$.each(defaults_general, function (key, value) {
GM_setValue(key, $('#aede_' + key).val());
});
$.each(defaults_modules, function (key, value) {
GM_setValue(key, $('#aede_' + key).is(':checked'));
});
resultConfig('¡Configuración guardada!');
});
},
resultConfig = function(result) {
$('#aede_result').remove();
$('#main_content').append('<p id="aede_result">'+result+'</p>');
},
resetConfig = function () {
$.each(defaults_general, function (key, value) {
GM_setValue(key, value);
});
$.each(defaults_modules, function (key, value) {
GM_setValue(key, value);
});
},
checkConfig = function () {
$.each(defaults_general, function (key, value) {
if (typeof GM_getValue(key) == 'undefined') {
GM_setValue(key, value);
}
});
$.each(defaults_modules, function (key, value) {
if (typeof GM_getValue(key) == 'undefined')
GM_setValue(key, value);
});
};
checkConfig();
if (document.location.href == 'http://hacknlove.github.io/anti-AEDE/') {
aedeConfig();
}else{
GM_xmlhttpRequest({
method:'GET',
onload:function(response){
main(
generateRegExp(
parseList(response.responseText)
)
);
},
url:GM_getValue('url_list')
});
}
});