Feedless Facebook

Remove the news feed from Facebook to prevent distraction

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name       Feedless Facebook
// @author     Adam Novak, miXwui
// @version    1.5
// @description Remove the news feed from Facebook to prevent distraction
// @include    /https?:\/\/www.facebook.com\/*/
// @noframes
// @run-at     document-end
// @grant      none
// @namespace https://greasyfork.org/users/22981
// ==/UserScript==

// (C) 2020 Adam Novak, miXwui
// MIT license
// Inspired by the Chrome extension "Feedless Facebook":
// https://github.com/owocki/feedlessfacebook

let hackPage = function() {
  let facebook = document.getElementById('facebook');
  if (facebook !== null) {
    // This is a real main Facebook page

    const main = facebook.querySelector('[role="main"]');

    // Find the newsfeed
    const newsfeed = facebook.querySelector('[role="feed"]');
    
    const hider = document.getElementById('hideFeed')

    if (main && newsfeed && !hider) {
      // This is a real main page we haven't done yet

      // Create a way to show and re-hide the news feed
      let button = document.createElement('button');
      button.id = 'hideFeed'
      newsfeed.parentNode.insertBefore(button, newsfeed)
      // Define a way to show and hide the news feed
      var feedShown = true
      let toggleFeed = function() {
        if (feedShown) {
          // Hide
          newsfeed.style.display='none';
          button.innerText = '[+] Show Newsfeed';
          feedShown = false;
        } else {
          // Show
          newsfeed.style.display='block';
          button.innerText = '[-] Hide Newsfeed';
          feedShown = true;
        }
      }
      // Toggle the feed when the button is clicked
      button.addEventListener('click', toggleFeed);
      // Actually hide the feed
      toggleFeed();
    }
  }
}

hackPage();

// Not sure the button disappears without a setTimeout
// A rerender or something is clearing out the added button element
// or something but I'm too lazy to spend the time to figure it out eh
setTimeout(hackPage, 1000);