Bangumi EpSpoilerFolder

折叠章节讨论中含"剧透"的楼层

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Bangumi EpSpoilerFolder
// @description 折叠章节讨论中含"剧透"的楼层
// @namespace   bangumi.scripts.prevails.EpSpoilerFolder
// @author      "Donuts."
// @include     /^https?:\/\/(bgm\.tv|bangumi\.tv|chii\.in)\/((m|rakuen)\/topic\/)?ep\/\d+$/
// @require     https://code.jquery.com/jquery-2.2.4.min.js
// @version     1.0.2
// @grant       GM_addStyle
// @encoding    utf-8
// ==/UserScript==

const $reply = $('.row_reply');

const regex = /(剧透|劇透|R\.?I\.?P|走好)/i;
const message = '可能有剧透!单击此处显示 / 隐藏';

$reply.each(function(){
    const $div = $('.message.clearit,.cmt_sub_content', this);
    const text = $div.text();
    if (text.match(regex)) {
        const $reply_content = $('.reply_content', this);
        $reply_content.hide();
        $reply_content.before(`<a class="ep_spoiler_fold_toggle" href="javascript:;">(+${$div.length - 1}) ${message}</a>`);
    }
});

$('.ep_spoiler_fold_toggle').click(function(){
    $(this).next().slideToggle();
});

GM_addStyle("a.ep_spoiler_fold_toggle {display:block;color:#bbb;margin-top:5px}");