Greasy Fork

Greasy Fork is available in English.

新版巴哈姆特清爽化 & 扩宽首页显示区域

清理新版巴哈姆特的广告、扩宽首页显示区域、移除页脚与浮动区块

当前为 2025-05-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         New Bahamut Cleaner & Homepage Content Widening
// @name:zh-TW   新版巴哈姆特清爽化 & 擴寬首頁顯示區域
// @name:zh-CN   新版巴哈姆特清爽化 & 扩宽首页显示区域
// @namespace    https://www.tampermonkey.net/
// @version      1.5
// @description  Cleans up ads on the new version of Bahamut, widens the homepage content area, and removes the footer and floating elements.
// @description:zh-TW 清理新版巴哈姆特的廣告、擴寬首頁顯示區域、移除頁腳與浮動區塊
// @description:zh-CN 清理新版巴哈姆特的广告、扩宽首页显示区域、移除页脚与浮动区块
// @author       ChatGPT
// @match        https://www.gamer.com.tw/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  const cleanBahaAds = () => {
    // ✅ 移除超級看板廣告
    const bannerImg = document.querySelector('#adunit img[alt="超級看板廣告"]');
    if (bannerImg) {
      const adContainer = bannerImg.closest('div.GoogleActiveViewElement');
      if (adContainer) adContainer.remove();
    }

    // ✅ 移除 billboardAd 廣告容器
    const gapContainer = document.querySelector('#billboardAd.BH-banner--lg');
    if (gapContainer) gapContainer.remove();

    // ✅ 移除右側廣告欄項目
    const rightAdItems = document.querySelectorAll('.main-container__right .BH-banner__item');
    rightAdItems.forEach(item => item.remove());

    const bannerRow = document.querySelector('.main-container__right .BH-banner__row');
    if (bannerRow) {
      bannerRow.style.minHeight = '0';
      bannerRow.style.padding = '0';
      bannerRow.style.margin = '0';
    }

    // ✅ 移除勇者福利社
    const fuliSection = document.querySelector('div.main-container__right > section.index-fuli');
    if (fuliSection) fuliSection.remove();

    // ✅ 移除右側浮動連結
    const fixedRightLinks = document.querySelectorAll('div.fixed-right div.column a.fixed-right__link');
    fixedRightLinks.forEach(link => link.remove());

    // ✅ 擴寬主貼文容器區域
    const mainRow = document.querySelector('main.main-container__row');
    if (mainRow) {
      mainRow.style.width = '126%';
      mainRow.style.margin = '0 auto';
    }

    const mainContent = document.querySelector('.main-index__content');
    if (mainContent) {
      mainContent.style.width = '100%';
      mainContent.style.maxWidth = '1350px';
    }

    // ✅ 隱藏主內容中的廣告容器(前提:確保不是唯一子元素)
    const postPanel = document.querySelector('#postPanel.section-index');
    if (postPanel) {
      const adWrappers = postPanel.querySelectorAll('.ad__wrapper');
      adWrappers.forEach(ad => {
        if (ad.parentElement?.children.length > 1) {
          ad.style.display = 'none';
        }
      });
    }

    // ✅ 保留圖片燈箱容器(.pswp)
    if (!document.querySelector('div.pswp')) {
      const pswp = document.createElement('div');
      pswp.className = 'pswp';
      document.body.appendChild(pswp);
    }

    // ✅ 移除頁腳
    const footer = document.querySelector('footer.main-container__footer');
    if (footer) footer.remove();
  };

  // ⏳ 延遲首次執行(避免過早干擾)
  setTimeout(() => cleanBahaAds(), 500);

  // ✅ 監聽主內容變動(比觀察整個 body 更精確)
  const mainContent = document.querySelector('.main-index__content');
  if (mainContent) {
    let debounceTimer = null;
    const observer = new MutationObserver(() => {
      clearTimeout(debounceTimer);
      debounceTimer = setTimeout(() => cleanBahaAds(), 200);
    });
    observer.observe(mainContent, { childList: true, subtree: true });
  }
})();