Greasy Fork

Greasy Fork is available in English.

游民星空去广告

remove AD. and change some styles !

当前为 2021-01-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         游民星空去广告
// @namespace    http://tampermonkey.net/
// @version      0.51
// @description  remove AD. and change some styles !
// @author       Wenhan
// @match        http://*.gamersky.com/*
// @match        https://*.gamersky.com/*
// @grant        none
// ==/UserScript==



(function() {
    'use strict';

    var gamersky = {
        // 设定要去除元素的选择器规则
        queryADArray : [
            ".onlyOneBgtgs", //主页背景广告
            "#ADback", //主广告
            '#adscontainer_banner_new_second_index_1060', // 主页通栏广告
            "#FuGai", //弹窗广告
            "#ADcover", //弹窗广告
            "#adTips", //右下提示广告
            '#new_page_allsite_620', // 详情页正文下方广告位
            '.ad_r' // 详情页推荐位广告
        ],
        state:{
            switchListener: null
        },

        // 黑天白天模式切换下的样式调整
        switchLightAndDark: function(){
            // 默认为白天模式
            var themeMode = 'light';
            // 黑天模式
            if(document.body.className.indexOf('hei')!==-1){
                themeMode = 'dark';
            }

            switch(themeMode){
                case 'light':
                    document.body.style.background = '#fff';
                    break;
                case 'dark':
                    document.body.style.background = '#333';
                    break;
            }

        }

    };
    gamersky.switchLightAndDark();


    // 监听所有dom变化
    new MutationObserver(function(mutations, observer){

        gamersky.queryADArray.forEach(function(item){
            document.querySelector(item) ? document.querySelector(item).remove() : null;
        });

        // 去除阴影样式
        if(document.querySelector('.Mid')){
            document.querySelector(".Mid").style.boxShadow = 'none';
        }


        // 白天黑天切换
        if(document.querySelector('#switch')){
            if(gamersky.state.switchListener){
                return;
            }
            gamersky.state.switchListener = true;
            document.querySelector('#switch').addEventListener('click',function(){
                gamersky.switchLightAndDark();
            },false);
        }

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

})();