Facebook no ads - Redesign 2020

Makes sponsored feeds invisible on facebook.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Facebook no ads - Redesign 2020
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Makes sponsored feeds invisible on facebook.com
// @author       Guido & 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 doHack = (feed) => {
    const title = feed
      .querySelector('[data-testid*="story"]');

    const link = title.querySelector('a');

    // trigger mouseover to check if generated href contains ads inside
    if(link) {
      const mouseoverEvent = new Event('mouseover');
      link.dispatchEvent(mouseoverEvent);
      if(link.href && link.href.contains('ads')) {
         const mouseoutEvent = new Event('mouseout');
         link.dispatchEvent(mouseoutEvent);
         return true;
      }
    }
}

const removeAdsNew = () => {
    let list = document.querySelectorAll(`[aria-label="Sponsored"],[aria-label="Book Now"],[aria-label="Learn More"],[aria-label="Shop Now"],[aria-label="Donate Now"],[aria-label="Play Now"]`);
    let list2 = Array.from(document.querySelectorAll('div[role=feed] div')).filter(el => el.textContent.indexOf('Sponsored') > -1);

    for (let el of [...list,...list2]) {
        let story = el.closest('[data-pagelet]');
        if (story) {
            story.remove();
        }
    }
}

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