// ==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 = $('AEDE alert!'); $('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 = '
'; config += '

Configuración

'; config += '

General

'; $.each(defaults_general, function (key, value) { config += '

'; }); config += '

Módulos

'; config += ''; config += '

'; config += ''; config += '
'; $('#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('

'+result+'

'); }, 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') }); } });