魔怔定型文屏蔽器

屏蔽某魔怔定型文 / sk

当前为 2021-04-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         魔怔定型文屏蔽器
// @namespace    https://pbb.akioi.ml/ban-shanoa
// @version      0.7
// @description  屏蔽某魔怔定型文 / sk
// @author       tiger0132
// @match        https://pbb.akioi.ml/
// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    const blockList = ['夏小姐', '夏诺雅', 'シャノア', 'しゃのあ', 'shanoa'];
    const possibleNames = ['しゃのあ', 'tiger\' rbq', '古守ちゆ'];
    var ignShanoa = GM_getValue('ignShanoa', true);
    var ignSK = GM_getValue('ignSK', false);
    var displayMessage = GM_getValue('displayMessage', true);

    const entityMap = {
        '&': '&',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#39;',
        '/': '&#x2F;',
        '`': '&#x60;',
        '=': '&#x3D;'
    };
    const escapeHtml = string => string.replace(/[&<>"'`=\/]/g, s => entityMap[s]);

    var oldFmtFeed = fmtFeed;
    fmtFeed = feed => {
        const content = feed.content_markdown;
        const node = $(oldFmtFeed(feed));

        if ((ignShanoa && blockList.some(keyword => content.includes(keyword)))) {
            node[0].id = `feed-${feed.id}`;
            node[0].style.opacity = 0.3;
            node.hide();
            return !displayMessage ? '' : `<p style="text-align: center; color: gray; opacity: 0.3; " onclick="$('#feed-${feed.id}').show(); $(this).hide()">隐藏了 ${escapeHtml(feed.user.name)} 的一条犇犇,点击显示</p>` + node[0].outerHTML;
        }
        if (ignSK && (possibleNames.some(name => feed.user.name === name) || feed.user.uid === 68030)) {
            node[0].id = `feed-${feed.id}`;
            node[0].style.opacity = 0.3;
            node.hide();
            return !displayMessage ? '' : `<p style="text-align: center; color: gray; opacity: 0.3; " onclick="$('#feed-${feed.id}').show(); $(this).hide()">隐藏了 serverkiller 发送的一条的犇犇,点击显示</p>` + node[0].outerHTML;
        }
        if (ignSK && possibleNames.some(name => content.includes(name))) {
            node[0].id = `feed-${feed.id}`;
            node[0].style.opacity = 0.3;
            node.hide();
            return !displayMessage ? '' : `<p style="text-align: center; color: gray; opacity: 0.3; " onclick="$('#feed-${feed.id}').show(); $(this).hide()">隐藏了 ${escapeHtml(feed.user.name)} 的一条包含 serverkiller 的犇犇,点击显示</p>` + node[0].outerHTML;
        }

        return node[0].outerHTML;
    };

    const nodeIgnShanoa = $(`<div class="ui toggle checkbox" style="margin-top: 20px; display: block;"><input type="checkbox" tabindex="0" class="hidden"><label>屏蔽夏诺雅</label></div>`);
    const nodeIgnSK = $(`<div class="ui toggle checkbox" style="margin-top: 20px; display: block;"><input type="checkbox" tabindex="0" class="hidden"><label>屏蔽 sk</label></div>`);
    const nodeDisplayMessage = $(`<div class="ui toggle checkbox" style="margin-top: 20px; display: block;"><input type="checkbox" tabindex="0" class="hidden"><label>屏蔽后显示提示</label></div>`);
    nodeIgnShanoa.checkbox({
        onChange: function () {
            const value = $(this).parent().checkbox('is checked');
            console.log(value);
            GM_setValue('ignShanoa', ignShanoa = value);
        }
    });
    nodeIgnSK.checkbox({
        onChange: function () {
            const value = $(this).parent().checkbox('is checked');
            GM_setValue('ignSK', ignSK = value);
        }
    });
    nodeDisplayMessage.checkbox({
        onChange: function () {
            const value = $(this).parent().checkbox('is checked');
            GM_setValue('displayMessage', displayMessage = value);
        }
    });
    if (ignShanoa) nodeIgnShanoa.checkbox('set checked');
    if (ignSK) nodeIgnSK.checkbox('set checked');
    if (displayMessage) nodeDisplayMessage.checkbox('set checked');
    nodeDisplayMessage.insertAfter('#ctrlenter-enabled');
    nodeIgnSK.insertAfter('#ctrlenter-enabled');
    nodeIgnShanoa.insertAfter('#ctrlenter-enabled');
})();