Hide "Follow posts" for Facebook.

Get rid of those annoying posts from those i'm not following

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Hide "Follow posts" for Facebook.
// @version      1.2
// @description  Get rid of those annoying posts from those i'm not following
// @match        https://www.facebook.com/*
// @grant        none
// @author       Cuong Tran
// @namespace https://greasyfork.org/en/users/1291782-tran-huu-phu-cuong
// ==/UserScript==

//Whenever the page changes
(function() {
    function onElementInserted(containerSelector, elementSelector, callback) {
        var onMutationsObserved = function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes && mutation.addedNodes.length) {
                    [].map.call(mutation.addedNodes, function(el) {
                        if (!el || !el.querySelector) return;
                         // console.log('New inserted element', el)
                          callback(el)
                        if (el.classList.contains('html-div')) {
                         // callback(el)
                        } else {
                          // var elements = el.querySelectorAll(elementSelector);
                          //for (var i = 0, len = elements.length; i < len; i++) {
                           // callback(elements[i]);
                          // }
                        }
                    });
                }
            });
        };

        var target = document.querySelector(containerSelector);
        var config = { childList: true, subtree: true };
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
        var observer = new MutationObserver(onMutationsObserved);
        observer.observe(target, config);
    }


    onElementInserted('body', 'div', function(element) {
        const els = Array.from(element.querySelectorAll('div[role="button"]'));

        if(els.some(el => el.innerHTML.contains('Follow'))) {
            element.firstChild.style.display = 'none';
            const newdiv = document.createElement('div');
            newdiv.innerHTML = `
            <div style="background: #fff3cd; margin-top: 4px; border: 1px solid #ffc107; padding: 8px 12px; border-radius: 4px; color: #856404; font-size: 14px;">1 post hidden. Rule: UNFOLLOWING AUTHOR</div>
            `
            element.appendChild(newdiv);
        }
        // if (element.innerText.substring(0,2) !== 'Ad') return;
        // console.log(element);
        //    element.style.display = "none";
    });

})();