Facebook 加寬貼文顯示區域

Facebook 加寬貼文顯示區域,將原本貼文兩側空白的部分填滿

安裝腳本?
作者推薦腳本

您可能也會喜歡 Facebook 清爽化

安裝腳本
// ==UserScript==
// @name         Facebook Widen Post Display Area
// @name:zh-TW   Facebook 加寬貼文顯示區域
// @name:zh-CN   Facebook 加宽贴文显示区域
// @name:JP      Facebook 投稿表示エリアの幅を広げる
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Facebook Widen Post Display Area and Fill the Blank Spaces on Both Sides of the Post
// @description:zh-TW Facebook 加寬貼文顯示區域,將原本貼文兩側空白的部分填滿
// @description:zh-CN Facebook 加宽贴文显示区域,将原本贴文两侧空白的部分填满
// @description:JP Facebook 投稿表示エリアの幅を広げ、投稿の両側の空白部分を埋める
// @author       chatgpt
// @match        https://www.facebook.com/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  // === 根基樣式注入 ===(不可更動)
  GM_addStyle(`
    /* === 貼文主要容器外框加寬 === */
    div.x78zum5.xdt5ytf.x1n2onr6.x1ja2u2z,
    {
      width: 100% !important;
      max-width: 100% !important;
    }

    /* === 貼文主要容器推文主軸 === */
    div.x193iq5w.xvue9z.xq1tmr.x1ceravr
    {
      width: auto !important;
      max-width: 100% !important;
    }
  `);

  // === 防抖函式 ===
  const debounce = (fn, delay) => {
    let timer = null;
    return (...args) => {
      clearTimeout(timer);
      timer = setTimeout(() => fn(...args), delay);
    };
  };

  // === 用於重新執行 GM_addStyle(確保延遲載入也有套用)===
  const reapplyStyles = debounce(() => {
    // 再次執行原始 GM_addStyle(完全不動原始內容)
    GM_addStyle(`
      /* === 貼文主要容器外框加寬 === */
      div.x78zum5.xdt5ytf.x1n2onr6.x1ja2u2z,
      {
        width: 100% !important;
        max-width: 100% !important;
      }

      /* === 貼文主要容器推文主軸 === */
      div.x193iq5w.xvue9z.xq1tmr.x1ceravr
      {
        width: auto !important;
        max-width: 100% !important;
      }
    `);
  }, 300);

  // === 監聽 DOM 變化(Facebook 首頁為 SPA,滾動或切換可能動態載入)===
  const observer = new MutationObserver(reapplyStyles);

  observer.observe(document.body, {
    childList: true,
    subtree: true
  });

  // === 初次載入後補一次樣式,避免 requestIdleCallback 不支援的情況 ===
  if ('requestIdleCallback' in window) {
    requestIdleCallback(reapplyStyles);
  } else {
    setTimeout(reapplyStyles, 500);
  }
})();