[Niko] Hide Custom Ranking Ads

2025年版ニコニコ カスタムランキングの広告行を非表示化

// ==UserScript==
// @name         [Niko] Hide Custom Ranking Ads
// @namespace    http://tampermonkey.net/
// @version      2025-04-10
// @description  2025年版ニコニコ カスタムランキングの広告行を非表示化
// @author       anonymous
// @match        https://www.nicovideo.jp/ranking/custom
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nicovideo.jp
// @grant        none
// @license      MIT
// ==/UserScript==

(async function() {
    'use strict';

    const AD_LINE_CLASS = '.w_100\\%.d_grid.grid-tc_\\{sizes\\.x5\\}_1fr_1fr_1fr_1fr_1fr.gap_base';

    //---------------------------------------------------------------
    function watchElementsToAction(query, action, doOnce){
        console.debug('watch: '+ query);

        function resultAction(query_result, observer){
            if(action && query_result){
                Array.from(query_result).forEach(
                    (elm)=>{ action(elm, observer); }
                );

                return true;
            }
            return false;
        };

        // 即実行
        if( resultAction(document.querySelectorAll(query)) && doOnce){
            console.debug('already exists and act done.');
            return null;
        }

        // 変化を監視
        const observer = new MutationObserver((mutations) => {
            Array.from(mutations).some((mutation) => {
                let found = false;
                Array.from(mutation.addedNodes).some((node) => {
                    if(typeof(node.parentNode.querySelectorAll) != 'function'){
                        console.debug("parent not have queryselector.")
                        return false;
                    }

                    const query_result = node.parentNode.querySelectorAll(query);
                    if(query_result.length > 0){
                        console.debug(query + " match!")
                        resultAction(query_result, observer);
                    }

                    if(doOnce){
                        observer.disconnect();
                    }
                });
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });

        return observer;
    }

    function waitForElements(query){
        return new Promise(
            (resolve) => {
                watchElementsToAction(
                    query,
                    (elements, observer) => {
                        if(observer){
                            observer.disconnect();
                        }
                        resolve(elements);
                    }
                );
            }
        ).then(
            (results) => {
                return results;
            }
        );
    }

    //--------------------------------
    function DelAdRow(element)
    {
        if (element.querySelector('svg')) {
            //console.log('SVG要素が含まれています');
        } else {
            element.style.display='none'
        }
    }

    watchElementsToAction(AD_LINE_CLASS, DelAdRow);


})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址