您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
清理新版巴哈姆特的广告(首页、GNN新闻、哈拉区)、扩宽显示区域(首页、GNN新闻、哈拉区)、移除页脚与无用的浮动区块
// ==UserScript== // @name New Bahamut Cleaner & Content Widening // @name:zh-TW 新版巴哈姆特乾淨化 & 擴寬顯示區域 // @name:zh-CN 新版巴哈姆特干净化 & 扩宽显示区域 // @namespace https://www.tampermonkey.net/ // @version 4.8 // @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 centerBanner = document.querySelector('div.main-index__content div.BH-banner.section-index'); if (centerBanner) centerBanner.remove(); // 移除中間廣告區 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(); // 移除 GNN 商店廣告 const banner4gamer = document.querySelector('div#banner-4gamer'); if (banner4gamer) banner4gamer.remove(); // 移除上方橫幅 const gptBanner = document.querySelector('div#div-gpt-ad-banner'); if (gptBanner) gptBanner.remove(); // 移除 GPT 廣告 const googleImageDiv = document.querySelector('div#google_image_div.GoogleActiveViewElement'); if (googleImageDiv) googleImageDiv.remove(); // 移除 Google 廣告容器 // 僅移除含有廣告內容的 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 cleanPostHeaderAds = () => { document.querySelectorAll('div.c-post__header').forEach(adBlock => { const hasAd = adBlock.querySelector( 'iframe[id^="google_ads_iframe"], iframe[src*="ads"], div[id^="google_ads_iframe"]' ); if (hasAd) adBlock.remove(); // 如果含有廣告 iframe,就移除整塊 header }); }; // ✅ 單篇文章頁持續監控:每 3 秒重新檢查是否有廣告殘留 const startPostHeaderAdCleaner = () => { setInterval(() => { cleanPostHeaderAds(); }, 3000); // 每 3 秒執行一次清理 }; // ===== 哈拉區模組(清除廣告)===== 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(); // 刪除廣告列 }); // 移除特定廣告容器 ['div#div-gpt-ad-banner', 'div#google_image_div.GoogleActiveViewElement', 'div#flySalve', 'div#BH-master div.forum-ad_top'] .forEach(sel => { const el = document.querySelector(sel); if (el) el.remove(); // 刪除匹配選擇器的廣告容器 }); // 🔒 避免誤刪搜尋結果頁面 if (location.pathname === '/search.php') return; // 一般廣告容器偵測:根據 id/class/html 內容是否包含廣告關鍵字 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; } /* 基礎圖片樣式:不超過容器,但不強制放大 */ .c-section__main img { max-width: 100%; height: auto; width: auto !important; image-rendering: auto; } /* 避免圖片超出容器邊界 */ .c-article__content img, .c-article__content a.photoswipe-image img, .c-post__body img { max-width: 100%; height: auto; display: block; } /* 單獨限制圖片容器寬度,不動整體段落 */ .c-article__content a.photoswipe-image { display: inline-block; max-width: 100%; } `; 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 }); return observer; } // ===== 網域初始化工具 ===== function initPage({ hostname, callback, observeSelector }) { if (location.hostname !== hostname) return; setTimeout(callback, delay); // 初次執行 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); if (pathname === '/C.php' && searchParams.has('bsn') && searchParams.has('snA')) { enhanceForumPost(); // 調整單篇文章頁樣式 cleanPostHeaderAds(); // 移除樓層廣告 observeWithDebounce( document.querySelector('.c-section__main'), cleanPostHeaderAds, delay ); startPostHeaderAdCleaner(); // ✅ 啟動定時監控廣告殘留 } if (pathname === '/B.php' && searchParams.has('bsn')) { enhanceForumList(); // 調整列表樣式 } }, delay); // 當討論串列表異動時,自動清除廣告 observeWithDebounce( document.querySelector('form div.b-list-wrap'), cleanForumAds, delay ); } })();