Facebook no ads

Makes sponsored feeds invisible on facebook.com

目前為 2019-03-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Facebook no ads
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Makes sponsored feeds invisible on facebook.com
// @author       Darmikon
// @match        https://www.facebook.com/*
// @grant        none
// ==/UserScript==

const throttle = (func, limit) => {
  let inThrottle
  return function() {
    const args = arguments
    const context = this
    if (!inThrottle) {
      func.apply(context, args)
      inThrottle = true
      setTimeout(() => inThrottle = false, limit)
    }
  }
}

const trimAds = () => {
    const feeds = document.getElementById('contentArea').querySelectorAll('[id*=hyperfeed_story_id]');
    feeds.forEach(feed => {
        try {
          const title = feed
                    .querySelector('[data-testid*="story"]');

          // feed_subtitle_263;376364045765261;0;2201380379930276;1552581075:5551613536253095581:5:0:11326
          const id = title.id || '';
          const hackSpace = id.split(';')[2];
          const detectAdsCondition = !title.id || hackSpace == 0;

          if(detectAdsCondition) {
            // console.log('killed', title);
            feed.style.display = "none";
          }

        } catch (e) {}
    });
}

(function() {
    const throttleKill = throttle(trimAds, 1000);
    throttleKill();
    window.addEventListener('scroll', throttleKill);
    window.addEventListener('resize', throttleKill);
})();