NGA-NoAd

去除NGA论坛广告

安裝腳本?
作者推薦腳本

您可能也會喜歡 NGA优化摸鱼体验

安裝腳本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NGA-NoAd
// @namespace    http://tampermonkey.net/
// @version      0.0.4
// @author       Githuboy
// @description  去除NGA论坛广告
// @license      MIT
// @require      https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
// @match        *://bbs.nga.cn/*
// @match        *://ngabbs.com/*
// @match        *://nga.178.com/*
// @grant       GM_addStyle
// @inject-into content
// ==/UserScript==

(function() {
    'use strict';
    var id =0;
    const _fixStyle = function(){
        GM_addStyle(".goodbad span[title]{color:inherit !important}")
    }
    var $ = window.jQuery||{};
    var findUrl = function(url){
        var idx = url.indexOf("?5");
        var len = 2;
        if(idx<0){
            idx = url.indexOf("?");
            len = 1;
        }
        if(idx<0){
            return "";
        }else{
            return url.substr(idx+len);
        }
    }
    //https://bbs.nga.cn/misc/adpage_insert_2.html?5https://bbs.nga.cn/read.php?tid=28126278
    //https://nga.178.com/misc/adpage_insert_2.html?https://nga.178.com/read.php?tid=35426260
    var url = window.location.href;
    if(url.includes("adpage")){
        var result = findUrl(url);
        if(result){
            window.location.href=result;
            return;
        }
    }
    var task = function(){
        var adImgs = $("img[src='https://img4.nga.178.com/ngabbs/nga_classic/admark.png']");
        var adLength = adImgs.length;
        if(adLength==0){
            clearInterval(id);
            setTimeout(function(){
                id = setInterval(task,100);
            },1500);
            return;
        }
        console.log("发现广告数量:"+adLength+",执行清理");
        $(adImgs).each((i,a)=>{
            var p =$(a).parent();
            if(p !=null){
                $(p).parent().remove();
            }
            else p.remove();
        })
    };
    _fixStyle();
    id = setInterval(task,100);
    // Your code here...
})();