New Bahamut Cleaner & Content Widening

Cleans up ads on the new version of Bahamut (Homepage, GNN News, and Forum), widens the content display area (Homepage, GNN News, and Forum), and removes the footer and unnecessary floating elements.

Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide AniGamer Screenshot Helper

Installer dette script
// ==UserScript==
// @name         New Bahamut Cleaner & Content Widening
// @name:zh-TW   新版巴哈姆特乾淨化 & 擴寬顯示區域
// @name:zh-CN   新版巴哈姆特干净化 & 扩宽显示区域
// @namespace    https://www.tampermonkey.net/
// @version      3.5
// @description  Cleans up ads on the new version of Bahamut (Homepage, GNN News, and Forum), widens the content display area (Homepage, GNN News, and Forum), and removes the footer and unnecessary floating elements.
// @description:zh-TW 清理新版巴哈姆特的廣告(首頁、GNN新聞、哈拉區)、擴寬顯示區域(首頁、GNN新聞、哈拉區)、移除頁腳與無用的浮動區塊
// @description:zh-CN 清理新版巴哈姆特的广告(首页、GNN新闻、哈拉区)、扩宽显示区域(首页、GNN新闻、哈拉区)、移除页脚与无用的浮动区块
// @author       ChatGPT
// @match        https://www.gamer.com.tw/*
// @match        https://gnn.gamer.com.tw/*
// @match        https://forum.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();
    }

    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';
        }
      });
    }

    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();
  };

  // ===== 新聞區模組(穩定)=====
  const cleanGNN = () => {
    const shop = document.querySelector('div#shop.lazyloaded');
    if (shop) shop.remove();

    const banner4gamer = document.querySelector('div#banner-4gamer');
    if (banner4gamer) banner4gamer.remove();

    const gptBanner = document.querySelector('div#div-gpt-ad-banner');
    if (gptBanner) gptBanner.remove();

    const googleImageDiv = document.querySelector('div#google_image_div.GoogleActiveViewElement');
    if (googleImageDiv) googleImageDiv.remove();

    // 僅移除內含廣告關鍵字的 GN-lbox2B 區塊
    document.querySelectorAll('div.GN-lbox2B').forEach(el => {
      const id = el.id || '';
      const html = el.innerHTML;
      const isAd = /ad|ads|gpt|google/i.test(id) || /google_ads_iframe|gpt|doubleclick|adservice|googlesyndication/i.test(html);
      if (isAd) el.remove();
    });

    const flySalve = document.querySelector('div#flySalve');
    if (flySalve) flySalve.remove();

    const bhSlave = document.querySelector('div#BH-slave');
    if (bhSlave) bhSlave.remove();

    const bhWrapper = document.querySelector('div#BH-wrapper');
    if (bhWrapper) {
      bhWrapper.style.maxWidth = '100%';
    }

    const bhMaster = document.querySelector('div#BH-master');
    if (bhMaster) {
      bhMaster.style.width = 'calc(100%)';
    }

    const gnTopimg = document.querySelector('div#BH-master div.GN-topimg');
    if (gnTopimg) {
      gnTopimg.style.width = '100%';
    }
  };

    // ===== 哈拉區模組(清除廣告)=====
    const cleanForumAds = () => {
    // 清除列表內的廣告列
    document.querySelectorAll('form div.b-list-wrap table.b-list tbody tr.b-list__row')
    .forEach(row => {
      if (row.querySelector('td.b-list_ad')) row.remove();
    });

    const topAd = document.querySelector('div#div-gpt-ad-banner');
      if (topAd) topAd.remove();

    const googleImageAd = document.querySelector('div#google_image_div.GoogleActiveViewElement');
      if (googleImageAd) googleImageAd.remove();

    const flySalve = document.querySelector('div#flySalve');
      if (flySalve) flySalve.remove();

    // 新增:移除所有含有廣告關鍵字的區塊(保險起見只限 div)
    document.querySelectorAll('div').forEach(div => {
    const id = div.id || '';
    const className = div.className || '';
    const html = div.innerHTML;

    const isAdLike = /ad|ads|gpt|google/i.test(id + ' ' + className);
    const containsAdContent = /google_ads_iframe|gpt|doubleclick|adservice|googlesyndication/i.test(html);

      if (isAdLike && containsAdContent) {
         div.remove();
    }
  });
};

  // ===== 哈拉區 C.php 模組(單篇貼文頁)=====
    const enhanceForumPost = () => {
    const bhWrapper = document.querySelector('#BH-wrapper');
    if (bhWrapper) bhWrapper.style.width = '100%';

    const bhMaster = document.querySelector('#BH-master');
    if (bhMaster) bhMaster.style.width = 'auto';

    const style = document.createElement('style');
          style.textContent = `
    .c-section__main {
    float: right;
    width: 1620px;
    text-align: left;
    box-sizing: border-box;
  }
    /* 強制修改 #BH-slave 寬度為 100px */
    #BH-slave {
    width: 100px !important;
  }
  `;
    document.head.appendChild(style);
  };

  // ===== 哈拉區 B.php 模組(討論串列表頁)=====
  const enhanceForumList = () => {
    const bhWrapper = document.querySelector('#BH-wrapper');
    if (bhWrapper) bhWrapper.style.width = '100%';

    const bhMaster = document.querySelector('#BH-master');
    if (bhMaster) bhMaster.style.width = '1600px';

    const style = document.createElement('style');
    style.textContent = `
      .b-imglist-wrap03 .b-list__main,
      .b-imglist-wrap03 .b-list-item .b-list__main {
        max-width: 100%;
      }

      .b-imglist-wrap03 .imglist-text {
        display: inline-block;
        width: 1100px;
        vertical-align: top;
      }
    `;
    document.head.appendChild(style);
  };

  // ===== 執行條件判斷與監聽 =====
  const delay = 100; // 延遲時間設定(毫秒)

  function observeWithDebounce(target, callback, delay = 100) {
    if (!target) return; // 若節點不存在則不執行

    let timer = null;
    const observer = new MutationObserver(() => {
      clearTimeout(timer); // 清除上一次的計時器
      timer = setTimeout(callback, delay); // 設定新的延遲執行
    });

    // 開始監聽 DOM 子節點變化(包含後代節點)
    observer.observe(target, { childList: true, subtree: true });
  }

  function initPage({ hostname, callback, observeSelector }) {
    if (location.hostname !== hostname) return; // 若網域不符合,跳過此段執行

    // 初次載入頁面時先執行一次清理函式
    setTimeout(callback, delay);

    // 找到目標節點並啟用 MutationObserver 偵測變動
    const target = document.querySelector(observeSelector);
    observeWithDebounce(target, callback, delay);
  }

  // ===== www.gamer.com.tw 首頁區塊清理 =====
  initPage({
    hostname: 'www.gamer.com.tw',
    callback: () => cleanBahaAds(), // 執行首頁廣告清理
    observeSelector: '.main-index__content' // 觀察主內容變化
  });

  // ===== gnn.gamer.com.tw 新聞區塊清理 =====
  initPage({
    hostname: 'gnn.gamer.com.tw',
    callback: () => cleanGNN(), // 執行 GNN 廣告與版面清理
    observeSelector: 'div#BH-wrapper' // 觀察 GNN 包裹區變化
  });

  // ===== forum.gamer.com.tw 哈拉區處理 =====
  if (location.hostname === 'forum.gamer.com.tw') {
    // 初始執行:廣告清理、依頁面路徑執行對應寬度調整功能
    setTimeout(() => {
      cleanForumAds(); // 執行哈拉區廣告清理

      const pathname = location.pathname;
      const searchParams = new URLSearchParams(location.search);

      // 單篇貼文頁面(C.php)加寬處理
      if (pathname === '/C.php' && searchParams.has('bsn') && searchParams.has('snA')) {
        enhanceForumPost(); // 套用貼文加寬樣式
      }

      // 討論串列表頁面(B.php)加寬處理(包含清單與縮圖模式)
      if (pathname === '/B.php' && searchParams.has('bsn')) {
        enhanceForumList(); // 套用列表加寬樣式
      }
    }, delay);

    // 啟用 MutationObserver 觀察討論串列表區變動,自動再次清理廣告
    observeWithDebounce(
      document.querySelector('form div.b-list-wrap'), // 討論串列表區 DOM
      () => cleanForumAds(), // 清理函式
      delay // 延遲時間
    );
  }
})();