Adervarul Curat

Hides annoying tabloid articles from the from the first page, and replaces naughty words with better ones

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Adervarul Curat
// @name:ro        Adervarul Curat
// @version        0.5
// @description    Hides annoying tabloid articles from the from the first page, and replaces naughty words with better ones
// @description:ro Ascunde articolele de tabloid de pe prima pagina, si inlocuieste cuvintele nepotrivite
// @author         Razvan Pat
// @match          http://adevarul.ro/*
// @require http://code.jquery.com/jquery-latest.js
// @require http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js
// @run-at document-end
// @namespace https://greasyfork.org/users/8565
// ==/UserScript==


$.fn.directText = function() {
    var str = '';

    this.contents().each(function() {
        if (this.nodeType == 3) {
            str += this.textContent || this.innerText || '';
        }
    });

    return str;
};

jQuery.extend(jQuery.expr[':'], { 
    containsText: function(node, index, meta) {
        if(node.nodeName.toLowerCase() == 'iframe') {
            return false;
        }
        return $(node).directText().indexOf(meta[3]) != -1;
    }
}); 

//Hide front page articles
$('span.category-tag:contains("click.ro")').parents('article').hide();
$('span.category-tag:contains("wowbiz.ro")').parents('article').hide();
$('span.category-tag:contains("Realitatea.net")').parents('article').hide();
$('span.category-tag:contains("cancan.ro")').parents('article').hide();
$('.antena-3-cross').hide();

var naughtyWords = [
    ['penisului', 'lalelei'],
    ['penisuri', 'lalele'],    
    ['penisul', 'laleaua'],
    ['penis', 'lalea'],
    ['sex oral', 'un desen'],
    ['sexualizate', 'înfrumusețate'],
    ['sexuală', 'frumoasă'],
    ['sexuale', 'florale'],
    ['sexului', 'florei'],
    ['sexul', 'flora'],
    ['sex', 'gem'],
    ['căcatul', 'ciocolata'],
    ['căcat', 'ciocolată'],
    ['în pielea goală', 'în șlapi'],
    ['organele genitale ale', 'culorile'],
    ['organele genitale', 'culorile'],
    ['organe genitale', 'culori'],
    ['pornografică', 'de râs'],
    ['pornografic', 'de râs'],
    ['porno', 'de comedie']
];

var allNaughty = [];

_.forEach(naughtyWords, function(word) {
    allNaughty.push(word);
    allNaughty.push([toTitleCase(word[0]), toTitleCase(word[1])]);
    allNaughty.push([capitalize(word[0]), capitalize(word[1])]);
});

_.forEach(allNaughty, function(word) {
    $('*:containsText("' + word[0] + '")').each(function() {
        var ihtml = $(this).text();   
        ihtml = ihtml.replace(new RegExp(word[0], 'g'), word[1]); 
        $(this).text(ihtml);                  
    });
});

function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

function capitalize(s) {
    return s.toUpperCase();
};