NicoMyTimeLineSmartView

マイページのニコレポから投稿以外を非表示化するスクリプト

当前为 2018-08-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NicoMyTimeLineSmartView
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  マイページのニコレポから投稿以外を非表示化するスクリプト
// @author       You
// @match        http://www.nicovideo.jp/my/top
// @grant        none
// @require      https://code.jquery.com/jquery-3.3.1.slim.js
// ==/UserScript==

// 広告類の非表示化
(function() {
    $("div[data-follow-container]").css("display","none");
    $("#personalFrameArea").css("display","none");
    $("#web_pc_footer").css("display","none");
})();

//===================================
// タイムラインの要素監視と縮小化
//===================================
window.onload = function(){
    var targets = document.getElementsByClassName("nicorepo-page");
    var target = targets[0];
    var itemCount = 0;

    function createdTimeLine(){
        var timeLineItems = $('.NicorepoTimelineItem');

        // 現在の表示件数を記憶(表示件数0に対応する)
        itemCount = timeLineItems.find("strong").length;

        // 表示件数が0件の場合、次の要素を取得するためリンクをクリックさせる
        if(itemCount == 0){
            $(".timeline-next-link")[0].click();
        }

        // 初回アクセス時の非表示処理
        $.each(timeLineItems,function(index,val){
            var checkElement = $(this).find("strong");
            if(checkElement.length == 0){
                $(this).css("display","none");
            }
        });

        var targetTimelines =  $('.NicorepoTimeline');
        var targetTimeline = targetTimelines[0];

        // 【さらに読み込む】後の非表示処理
        function addTimeLineItem(){
            // 非表示処理済み以外の要素を取得する
            var addTimeLineItems = $('.NicorepoTimelineItem:not(display)');

            // 前回の縮小処理時と対象要素数が一致した場合は、
            // 【さらに読む込む】のリンクをクリックする
            if(addTimeLineItems.find("strong").length == itemCount){
                $(".timeline-next-link")[0].click();
            }
            itemCount = addTimeLineItems.find("strong").length;

            // 非表示処理
            $.each(addTimeLineItems,function(index,val){
                var checkItemElement = $(this).find("strong");
                var checkAttr = $(this).attr("display");
                if(checkItemElement.length == 0 && checkAttr != "none"){
                    $(this).css("display","none");
                }
            });
            itemCount = addTimeLineItems.find("strong").length;
        }
        var itemMO = new MutationObserver(addTimeLineItem);
        // NicorepoTimelineへの要素の追加の監視を開始
        itemMO.observe(targetTimeline, {childList: true});
    }
    var timeLineMO = new MutationObserver(createdTimeLine);
    // nicorepo-pageへの要素の追加の監視を開始
    timeLineMO.observe(target, {childList: true});
};