Facebook Filter

Hide Facebook posts you don't wanna see.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name           Facebook Filter
// @namespace      namespace
// @author         sanhbkdn
// @icon           https://cdn3.iconfinder.com/data/icons/free-social-icons/67/facebook_circle_color-128.png
// @description    Hide Facebook posts you don't wanna see.
// @include        http://www.facebook.com/*
// @include        https://www.facebook.com/*
// @exclude        https://www.facebook.com/permalink.php*
// @grant          GM_notification
// @version 0.0.1.20180529152542
// ==/UserScript==

// Install:
// Step 1: Install TamperMonkey
// Step 2: In Chrome, go to chrome://extensions/
// Step 3: Click on TamperMonkey options
// Step 4: Go to new user script tab.
// Step 5: Paste this script into it and save.

// Notes:
// To add more keywords to the blacklist, simply add
// more elements to the blacklist array at the start of
// this script.

const keywords = [ 'giá', 'bán', 'ship', 'hàng', 'khách', 'Sở hữu', 'mụn', 'lông', 'nám', 'tóc', 'thâm'];

const len = keywords.length;

const notificationDetails = {
    text: 'Blocked',
    title: 'Facebook Filter',
    timeout: 15000,
    onclick: function() { },
};

function contains(keywords, str) {
    let indexOfMatch;
    let keyBlocked;
    for (let i = len - 1; i >= 0; i--) {
        // add spaces at before and after each word to be more precise
        // (ex: ' giá '!= 'giáo'), some words do not need extra spaces
        indexOfMatch = str.search(' ' + keywords[i].toUpperCase() + ' ');
        keyBlocked = '';
        if (indexOfMatch >= 0) {
            for(let j = 0; j < 10; j++){
                if(typeof str[indexOfMatch] === "undefined") break;
                keyBlocked += str[indexOfMatch++];
            }
            console.log("[KeyBlocked] "+ keyBlocked);
            return true;
        }
    }
    return false;
}

function hidePostsByKeywords(black_list) {
    let posts = document.getElementsByClassName('userContentWrapper');
    for (let i = posts.length - 1; i >= 0; i--) {
        if(posts[i].style.display == 'none') continue;

        let content, url;

        if(typeof(posts[i].getElementsByClassName("userContent")[0]) == 'undefined'){
            continue;
        }

        content = posts[i].getElementsByClassName("userContent")[0].textContent;
        if (contains(black_list, content.toUpperCase())) {
            url = posts[i].getElementsByClassName("_5pcq")[0].href;
            posts[i].style.display = 'none';

            notificationDetails.text = "[Blocked] " + content;
            notificationDetails.onclick = function(){
                window.open(url, '_blank');
            };
            GM_notification(notificationDetails);
        }
    }
}
window.addEventListener("DOMNodeInserted", function() { hidePostsByKeywords(keywords); }, false);