Whisper Filter

Lets you hide every message except the whispers between you and another user

目前為 2016-06-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Whisper Filter
// @namespace    com.resterman
// @version      0.1
// @description  Lets you hide every message except the whispers between you and another user
// @author       resterman
// @match        http://www.kongregate.com/games/*/*
// @grant        none
// ==/UserScript==

/* jshint esnext: true */

(function() {
    'use strict';
    checkHolodeck();
})();

function checkHolodeck() {
    if (typeof holodeck !== "undefined" && holodeck.ready) init();
    else setTimeout(checkHolodeck, 100);
}

function init() {
    'use strict';
    Holodeck.prototype.showConversationWith = function (user) {
        if (this.showingConversationWith == user) this.showAllMessages();
        else this.showWhispersOnly(user);
    };

    Holodeck.prototype.showAllMessages = function () {
        this.activeDialogue()._message_window_node.select('.chat-message')
            .map(x => x.show());

        this.showingConversationWith = null;
    };

    Holodeck.prototype.showWhispersOnly = function (user) {
        this.showingConversationWith = user;

        this.activeDialogue()._message_window_node.select('.chat-message')
            .map(x => x.hide())
            .filter(x => x.select('.whisper').length > 0)
            .filter(x => {
                var u = x.select('.username');
                return u.length > 0 && new RegExp(user, 'i')
                    .test(u[0].readAttribute('username'));
            })
            .map(x => x.show());
    };

    Holodeck.prototype.getWhisperUsers = function () {
        var users = this.activeDialogue()._message_window_node.select('.chat-message')
            .filter(x => x.select('.whisper').length > 0)
            .map(x => x.select('.username')[0].readAttribute('username').toLowerCase());

        return new Set(users);
    };

    ChatDialogue.prototype.receivedPrivateMessage = function(a) {
        if (a.data.success) {
            var b = this;
            this._holodeck.filterIncomingMessage(a.data.message, function(c) {
                b.displayUnsanitizedMessage(a.data.from, c + '&nbsp; (<a class="reply_link" onclick="if (!event.ctrlKey) { holodeck.insertPrivateMessagePrefixFor(\'' + a.data.from + '\');} else { holodeck.showConversationWith(\'' + a.data.from.toLowerCase() + '\') };return false;" href="#">reply</a>)', {
                    "class": "whisper received_whisper"
                }, {
                    whisper: !0
                });
            });
        } else this.kongBotMessage(a.data.to + " cannot be reached. Please try again later.");
    };

    holodeck.addChatCommand('wf', function (a, b) {
        var args = b.split(' ');
        if (args.length >= 2) {
            var username = null;
            for (var user of holodeck.getWhisperUsers()) {
                if (new RegExp('^' + args[1].toLowerCase(), 'i').test(user)) {
                    username = user;
                    break;
                }
            }

            if (username) {
                holodeck.showConversationWith(username.toLowerCase());
            } else {
                holodeck.activeDialogue().displayMessage(
                    "Whisper Filter",
                    "You have no whispers with " + args[1],
                    {"class": "whisper received_whisper"},
                    {non_user: !0}
                );
            }
        } else holodeck.showAllMessages();

        return !1;
    });
}