B站评论区剧透折叠

折叠评论中含"剧透"的楼层

目前為 2017-12-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               Bilibili Comment Spoiler Folder
// @name:zh-CN         B站评论区剧透折叠
// @name:zh-HK         B站评论区剧透折叠
// @name:zh-TW         B站评论区剧透折叠
// @namespace          https://github.com/ipcjs
// @version            1.0.1
// @description        折叠评论中含"剧透"的楼层
// @description:zh-CN  折叠评论中含"剧透"的楼层
// @description:zh-HK  折叠评论中含"剧透"的楼层
// @description:zh-TW  折叠评论中含"剧透"的楼层
// @author             ipcjs
// @include            *://www.bilibili.com/video/av*
// @include            *://bangumi.bilibili.com/anime/*
// @include            *://bangumi.bilibili.com/movie/*
// @include            *://www.bilibili.com/bangumi/play/ep*
// @require            https://code.jquery.com/jquery-2.2.4.min.js
// @require            https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// @grant              GM_addStyle
// ==/UserScript==

'use strict'
GM_addStyle("a.ep_spoiler_fold_toggle {display:block;color:#bbb;margin-top:5px}")
const regex = /(剧透|劇透|R\.?I\.?P|走好)/i
const message = '可能有剧透!单击此处显示 / 隐藏'
$('.comm').arrive('.list-item.reply-wrap', ele => {
    // 处理剧透
    const processSpoiler = (replyCount) => {
        if ($('.ep_spoiler_fold_toggle', ele).length > 0) return // 已经添加了剧透警告, 着不需要再处理了

        const $content = $('.con', ele).find('>.text, >.info, >.reply-box, >.paging-box')
        $content.hide()
        $($content[0]).before(`<a class="ep_spoiler_fold_toggle" href="javascript:">(+${replyCount}) ${message}</a>`)
        $('.ep_spoiler_fold_toggle', ele).on('click', (event) => {
            $content.slideToggle()
        })
    }
    // 检测已有的文本
    $text = $('.text, .text-con', ele)
    if ($text.text().match(regex)) {
        processSpoiler($text.length - 1)
    }
    // 检测将来增加的文本
    ele.arrive('.text, .text-con', text => {
        if ($(text).text().match(regex)) {
            processSpoiler('x')
        }
    })

})