Greasy Fork is available in English.

兔区&闲情助手

屏蔽/高亮/记忆楼层/恢复输入/标记楼主/隐藏图片/修改配色/人数统计……

目前為 2021-12-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name          兔区&闲情助手
// @author        岚浅浅
// @description   屏蔽/高亮/记忆楼层/恢复输入/标记楼主/隐藏图片/修改配色/人数统计……
// @namespace     http://tampermonkey.net/
// @version       1.3.4
// @require       http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js
// @include       *://bbs.jjwxc.net/*
// ==/UserScript==

/* jshint esversion: 6 */

const SEPARATOR = ' ';
const SKIN_COUNT = 2;

const IS_BOARD_PAGE = location.href.indexOf('board.php') > 0;
const IS_POST_PAGE = location.href.indexOf('showmsg.php') > 0;
const IS_SEARCH_PAGE = location.href.indexOf('search.php') > 0;

const BOARD_ID = IS_BOARD_PAGE || IS_POST_PAGE ? getParamValue('board') : '';
const POST_ID = IS_POST_PAGE ? getParamValue('id') : '';
const PAGE_ID = IS_POST_PAGE ? getParamValue('page') || '0' : '';

const MATCHES = IS_POST_PAGE ? $('#msgsubject').text().match(/主题:(.*)\[(\d+)\]/) : '';
const PREFIX = IS_POST_PAGE ? BOARD_ID + '_' + POST_ID + '_' + MATCHES[1] : '';
const REPLY_COUNT = IS_POST_PAGE ? MATCHES[2] : '';

var Style = {
    initBeforeLoading() {
        Style.addSkin();
        Style.addMyStyle();
    },
    init() {
        Style.shieldAd();
    },
    addGlobalStyle(css) {
        var head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        var style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    },
    addSkin() {
        let skinId = getConfig('SkinId', '1');
        if (skinId === '1') {
            Style.addGlobalStyle(`
                /* 背景颜色 */
                body, td, input, textarea {
                    background-color: #2F393C !important;
                }
                /* 字体颜色 */
                * {
                    color: #616161;
                }
                #msgsubject, #topic, .replybodyinner, .landlord, a, span, input, textarea {
                    color: #A8C023 !important;
                }
                /* 边框颜色 */
                input, table[border="4"] {
                    border: solid 1px;
                }
                /* 修改头像 */
                .image1, .image2, .image6, .image7, .image8, .image9, .image10, .image12, .image13, .image14, .image15, .image16 {
                    background-image: url(https://i.loli.net/2018/08/28/5b84af69b2b16.png) !important;
                }
                .image17, .image18, .image19, .image20, .image21, .image22, .image23, .image24 {
                    background-image: url(https://i.loli.net/2018/08/28/5b84af682e7eb.png) !important;
                }
            `);
        }
        if (skinId !== '0') {
            if (IS_BOARD_PAGE) {
                document.title = BOARD_ID;
            }
        }
    },
    addMyStyle() {
        Style.addGlobalStyle(`
            .clickable {
                z-index: 999999;
                position: fixed;
                right: 10px;
                width: 180px;
                display: flex;
                flex-direction:column;
                opacity: 0.6;
                border: 1px solid #a38a54;
                border-radius: 3px;
            }
            .clickable div {
                margin: 2px auto;
            }
            .clickable a {
                margin: auto;
                cursor: pointer;
            }
            #hide-toolbar{
                top: 10px;
                width: 20px;
            }
            #toolbar{
                top: 10px;
            }
            #toolbar input {
                padding-left: 3px;
                width: 120px;
                height: 20px;
                font-size: 10px;
            }
            #white-keywords-wrap, #spam-keywords-wrap {
                display: none;
            }
            #white-keywords-wicket, #spam-keywords-wicket {
                top: 180px;
                overflow-y: auto;
                max-height: 730px;
            }
            #spam-keywords-wicket::-webkit-scrollbar, #white-keywords-wicket::-webkit-scrollbar {
                display: none;
            }
            .add-spam-post-btn, .board-report-btn {
                font-size: small;
            }
            .keyword-operation {
                font-size: small;
            }
        `);
    },
    shieldAd() {
        if (IS_BOARD_PAGE) {
            $('body > table:nth-child(4) > tbody > tr:nth-child(4), body > table:nth-child(5) > tbody > tr:nth-child(4)').hide();
        } else if (IS_POST_PAGE) {
            $('#imgurl, .textbook').hide();
        } else if (IS_SEARCH_PAGE) {
            $('body > table:nth-child(4) > tbody > tr:nth-child(4)').hide();
        }
    },
    switchToolbar() {
        if (getConfig('HideToolbar') == 'true') {
            setConfig('HideToolbar', false);
        } else {
            setConfig('HideToolbar', true);
        }
        Style.showToolbar();
    },
    showToolbar() {
        if (getConfig('HideToolbar') == 'true') {
            $('#hide-toolbar').show();
            $('#toolbar').hide();
        } else {
            $('#hide-toolbar').hide();
            $('#toolbar').show();
        }
    },
    switchSkin() {
        let oldSkinId = parseInt(getConfig('SkinId', '1'));
        let newSkinId =(oldSkinId + 1) % SKIN_COUNT;
        setConfig('SkinId', newSkinId);
        location.reload();
    }
};

var Toolbar = {
    init() {
        if (IS_BOARD_PAGE) {
            Toolbar.addBoardToolbar();
        } else if (IS_POST_PAGE) {
            Toolbar.addPostToolbar();
        }
        Toolbar.eventRegister();
    },
    addBoardToolbar() {
        $('body').append(`
                <div id="hide-toolbar" class="clickable">
                    <div>
                        <a id="toolbar-switch">助</a>
                    </div>
                </div>
            `);
        $('body').append(`
                <div id="toolbar" class="clickable">
                    <div>
                        <a id="toolbar-switch">隐藏助手</a>
                        <a id="skin-switch">切换皮肤</a>
                    </div>
                    <div>
                        <a id="go-top-btn">到顶部</a>
                        <a id="go-bottom-btn">到底部</a>
                        <a id="count-people-btn">人数统计</a>
                    </div>
                    <div>
                        <input id="post-id-jump-input" placeholder="输入贴子ID,直接跳转">
                        <a id="post-id-jump-btn">跳转</a>
                    </div>
                    <div>
                        <input id="add-white-keywords-input" placeholder="添加白名单,空格隔开">
                        <a id="add-white-keywords-btn">确定</a>
                    </div>
                    <div>
                        <input id="add-spam-keywords-input" placeholder="添加屏蔽词,空格隔开">
                        <a id="add-spam-keywords-btn">确定</a>
                    </div>
                    <div>
                        <a id="show-white-keywords-btn">查看白名单</a>
                        <a id="show-spam-keywords-btn">查看屏蔽词</a>
                    </div>
                </div>
                <div id="white-keywords-wrap">
                    <div id="white-keywords-wicket" class="clickable"/>
                </div>
                <div id="spam-keywords-wrap">
                    <div id="spam-keywords-wicket" class="clickable"/>
                </div>
            `);
        Style.showToolbar();
    },
    addPostToolbar() {
        $('body').append(`
                <div id="hide-toolbar" class="clickable">
                    <div>
                        <a id="toolbar-switch">助</a>
                    </div>
                </div>
            `);
        $('body').append(`
                <div id="toolbar" class="clickable">
                    <div>
                        <a id="toolbar-switch">隐藏助手</a>
                        <a id="imgs-hidden-switch">隐藏图片</a>
                    </div>
                    <div>
                        <a id="go-top-btn">到顶部</a>
                        <a id="go-bottom-btn">到底部</a>
                        <a id="count-people-btn">人数统计</a>
                    </div>
                    <div>
                        <input id="add-white-keywords-input" placeholder="添加白名单,空格隔开">
                        <a id="add-white-keywords-btn">确定</a>
                    </div>
                    <div>
                        <input id="add-spam-keywords-input" placeholder="添加屏蔽词,空格隔开">
                        <a id="add-spam-keywords-btn">确定</a>
                    </div>
                    <div>
                        <a id="show-white-keywords-btn">查看白名单</a>
                        <a id="show-spam-keywords-btn">查看屏蔽词</a>
                    </div>
                    <div>
                        <a id="keywords-highlighted-switch">贴内高亮</a>
                        <a id="pre-highlight-keyword-btn">前一个</a>
                        <a id="next-highlight-keyword-btn">后一个</a>
                    </div>
                </div>
                <div id="white-keywords-wrap">
                    <div id="white-keywords-wicket" class="clickable"/>
                </div>
                <div id="spam-keywords-wrap">
                    <div id="spam-keywords-wicket" class="clickable"/>
                </div>
            `);
        Style.showToolbar();
        if (BOARD_ID !== '2') {
            $('#report-btn-wrap').hide();
        }
    },
    eventRegister() {
        $(document).on('click', '#toolbar-switch', function() {
            Style.switchToolbar();
        });
        $(document).on('click', '#skin-switch', function() {
            Style.switchSkin();
        });

        $(document).on('click', '#go-top-btn', function() {
            scrollTo(0);
        });
        $(document).on('click', '#go-bottom-btn', function() {
            scrollTo($(document).height());
        });
        $(document).on('click', '#count-people-btn', function() {
            countPeople();
        });

        $(document).on('keypress', '#post-id-jump-input', function(event) {
            if (event.keyCode == 13) {
                jumpToPost();
            }
        });
        $(document).on('click', '#post-id-jump-btn', function() {
            jumpToPost();
        });

        $(document).on('keypress', '#add-white-keywords-input', function(event) {
            if (event.keyCode == 13) {
                Keyword.addWhiteKeywords();
            }
        });
        $(document).on('click', '#add-white-keywords-btn', function() {
            Keyword.addWhiteKeywords();
        });

        $(document).on('keypress', '#add-spam-keywords-input', function(event) {
            if (event.keyCode == 13) {
                Keyword.addSpamKeywords();
            }
        });
        $(document).on('click', '#add-spam-keywords-btn', function() {
            Keyword.addSpamKeywords();
        });

        $(document).on('click', '#show-white-keywords-btn', function() {
            Keyword.switchWhiteKeywordsWicket();
        });
        $(document).on('click', '#show-spam-keywords-btn', function() {
            Keyword.switchSpamKeywordsWicket();
        });

        $(document).on('click', '#report-btn', function() {
            window.open("https://ceorabbit.zz11.43ns.com/ReportCenter/2.php?id=" + POST_ID);
        });

        $(document).on('click', '#imgs-hidden-switch', function() {
            Img.switchImgsHidden();
        });

        $(document).on('click', '#keywords-highlighted-switch', function() {
            Keyword.switchKeywordsHighlighted();
        });
        $(document).on('click', '#pre-highlight-keyword-btn', function() {
            Keyword.preHighlightKeyword();
        });
        $(document).on('click', '#next-highlight-keyword-btn', function() {
            Keyword.nextHighlightKeyword();
        });
    }
};

var Img = {
    init() {
        if (getPostConfig('ImgsHidden')) {
            Img.switchImgsHidden();
        }
    },
    switchImgsHidden() {
        if ($('#imgs-hidden-switch').text() === '隐藏该贴图片') {
            $('img').hide();
            $('#imgs-hidden-switch').text('显示该贴图片');
            setPostConfig('ImgsHidden', true);
        } else {
            $('img').show();
            $('#imgs-hidden-switch').text('隐藏该贴图片');
            deletePostConfig('ImgsHidden');
        }
    }
};

var Landlord = {
    init() {
        var landlord = $('.authorname').eq(0).find('font').eq(2).text();
        if (landlord == '于') {
            return;
        }
        $('font').each(function() {
            if($(this).text() == landlord) {
                $(this).parent().find('font').eq(1).after('<font class="landlord">[楼主]</font>');
            }
        });
    }
};

var Floor = {
    init() {
        Floor.goSavedFloor();
        Floor.eventRegister();
    },
    getCurrentFloor() {
        let scrollTop = $(document).scrollTop();
        let nodes = $('.authorname').toArray();
        for (let node of nodes) {
            let nodeTop = $(node).parent().prev().prev().offset().top;
            if (nodeTop > scrollTop) {
                return parseInt($(node).find('font')[0].innerText.substring(1));
            }
        }
        return parseInt($(nodes.pop()).find('font')[0].innerText.substring(1));
    },
    goSavedFloor() {
        let floor = getPostConfig('Floor');
        if (floor) {
            let pageId = parseInt((floor - 1) / 300);
            if (pageId === parseInt(PAGE_ID)) {
                let node = $('.authorname').toArray().filter(e => $(e).find('font')[0].innerText.substring(1) === floor);
                scrollTo($(node).parent().prev().prev().offset().top);
                deletePostConfig('Floor');
            } else {
                window.open(`https://bbs.jjwxc.net/showmsg.php?board=${BOARD_ID}&id=${POST_ID}&page=${pageId}`);
            }
        }
    },
    eventRegister() {
        $(document).on('click', 'a[class^="quotereply"]', function() {
            setPostConfig('Floor', $(this).parent().prev().find('font')[0].innerText.substring(1));
        });
    }
};

var Keyword = {
    hasRenderWhiteKeywordsWicket: false,
    hasRenderSpamKeywordsWicket: false,
    hasRenderHighlightKeywordsPosition: false,
    init() {
        if (IS_BOARD_PAGE) {
            Keyword.highlightAndShieldBoardKeywords();
        } else if (IS_POST_PAGE) {
            if (getPostConfig('KeywordsHighlighted')) {
                Keyword.switchKeywordsHighlighted();
            }
        }
        Keyword.eventRegister();
    },
    highlightAndShieldBoardKeywords() {
        let whiteKeywords = getConfigItems('WhiteKeywords');
        let spamKeywords = getConfigItems('SpamKeywords');
        let spamPosts = getConfigItems('SpamPosts');
        let nodes = $('#msglist').children().children().toArray();
        nodes.shift();
        for (let node of nodes) {
            let reportNode = $(node).find('td')[1];
            let titleNode = $(node).find('td')[3];
            let url = $(titleNode).children().attr('href');
            let id = getParamValue('id', url);
            if (BOARD_ID === '2') {
                $(reportNode).children().remove();
            }
            $(reportNode).append(`<a class="add-spam-post-btn" id="${id}" href="javascript:void(0);">屏蔽</a>`);
            let title = titleNode.innerText;
            let needHighlight = false;
            for (let whiteKeyword of whiteKeywords) {
                if (title.indexOf(whiteKeyword) >= 0) {
                    $(node).css('opacity', '0.75');
                    needHighlight = true;
                    console.log(`已高亮(${whiteKeyword}):${title}`);
                    break;
                }
            }
            if (!needHighlight) {
                for (let spamKeyword of spamKeywords) {
                    if (title.indexOf(spamKeyword) >= 0) {
                        $(node).remove();
                        console.log(`已过滤(${spamKeyword}):${title}`);
                        break;
                    }
                }
            }
            for (let spamPost of spamPosts) {
                if (spamPost === id) {
                    $(node).remove();
                    console.log(`已过滤:${title}`);
                    break;
                }
            }
        }
    },
    switchKeywordsHighlighted() {
        if ($('#keywords-highlighted-switch').text() == '贴内高亮') {
            if (!Keyword.hasRenderHighlightKeywordsPosition) {
                Keyword.renderHighlightKeywordsPosition();
            }
            $('.highlight-keyword').css('cssText', 'color: #BC3F3C !important');
            $('#keywords-highlighted-switch').text('取消高亮');
            setPostConfig('KeywordsHighlighted', true);
        } else {
            $('.highlight-keyword').css('cssText', 'color: ;');
            $('#keywords-highlighted-switch').text('贴内高亮');
            deletePostConfig('KeywordsHighlighted');
        }
    },
    renderWhiteKeywordsWicket() {
        let whiteKeywords = getConfigItems('WhiteKeywords');
        let html = whiteKeywords.map(whiteKeyword => {
            return `
                    <div>
                        <label>${whiteKeyword}</label>
                        <a class='keyword-operation switch-white-keyword-in-post-btn' title='设置该白名单是否在贴内高亮'>贴内${hasConfigItem('WhiteKeywordsCloseInPost', whiteKeyword) ? '-' : '+'}</a>
                        <a class='keyword-operation delete-white-keyword-btn'>删除</a>
                    </div>
                `;
        }).join('');
        $('#white-keywords-wicket').html(html);
    },
    renderSpamKeywordsWicket() {
        let spamKeywords = getConfigItems('SpamKeywords');
        let html = spamKeywords.map(spamKeyword => {
            return `
                    <div>
                        <label>${spamKeyword}</label>
                        <a class='keyword-operation switch-spam-keyword-in-post-btn' title='设置该屏蔽词是否在贴内生效'>贴内${hasConfigItem('SpamKeywordsOpenInPost', spamKeyword) ? '-' : '+'}</a>
                        <a class='keyword-operation delete-spam-keyword-btn'>删除</a>
                    </div>
                `;
        }).join('');
        $('#spam-keywords-wicket').html(html);
    },
    renderHighlightKeywordsPosition() {
        let whiteKeywords = getConfigItems('WhiteKeywords');
        let spamKeywordsOpenInPost = getConfigItems('SpamKeywordsOpenInPost');
        let nodes = $('#topic, .quotebodyinner, .replybodyinner').toArray();
        for (let node of nodes) {
            for (let whiteKeyword of whiteKeywords) {
                if (!hasConfigItem('WhiteKeywordsCloseInPost', whiteKeyword)) {
                    $(node).html($(node).html().replace(new RegExp(whiteKeyword, 'g'), `<span class="highlight-keyword">${whiteKeyword}</span>`));
                }
            }
            for (let spamKeywordOpenInPost of spamKeywordsOpenInPost) {
                if (node.innerText.indexOf(spamKeywordOpenInPost) >= 0) {
                    $(node).parent().remove();
                    break;
                }
            }
        }
        Keyword.hasRenderHighlightKeywordsPosition = true;
    },
    addWhiteKeywords() {
        let newWhiteKeywords = $('#add-white-keywords-input').val().trim().replace(/\s+/g, SEPARATOR);
        if (newWhiteKeywords === '') {
            alert('请输入要添加的白名单关键词!');
            return;
        }
        addConfigItem('WhiteKeywords', newWhiteKeywords);
        $('#add-white-keywords-input').val('');
        Keyword.showWhiteKeywordsWicket();
        Keyword.hasRenderHighlightKeywordsPosition = false;
    },
    addSpamKeywords() {
        let newSpamKeywords = $('#add-spam-keywords-input').val().trim().replace(/\s+/g, SEPARATOR);
        if (newSpamKeywords === '') {
            alert('请输入要添加的待屏蔽关键词!');
            return;
        }
        addConfigItem('SpamKeywords', newSpamKeywords);
        $('#add-spam-keywords-input').val('');
        Keyword.showSpamKeywordsWicket();
    },
    deleteWhiteKeyword(node) {
        let whiteKeyword = $(node).prev().prev().text();
        $(node).parent().remove();
        removeConfigItem('WhiteKeywords', whiteKeyword);
        Keyword.showWhiteKeywordsWicket();
        Keyword.hasRenderHighlightKeywordsPosition = false;
    },
    deleteSpamKeyword(node) {
        let spamKeyword = $(node).prev().prev().text();
        $(node).parent().remove();
        removeConfigItem('SpamKeywords', spamKeyword);
        Keyword.showSpamKeywordsWicket();
    },
    switchWhiteKeywordInPost(node) {
        let whiteKeyword = $(node).prev().text();
        if (hasConfigItem('WhiteKeywordsCloseInPost', whiteKeyword)) {
            removeConfigItem('WhiteKeywordsCloseInPost', whiteKeyword);
        } else {
            addConfigItem('WhiteKeywordsCloseInPost', whiteKeyword);
        }
        Keyword.showWhiteKeywordsWicket();
        Keyword.hasRenderHighlightKeywordsPosition = false;
    },
    switchSpamKeywordInPost(node) {
        let spamKeyword = $(node).prev().text();
        if (hasConfigItem('SpamKeywordsOpenInPost', spamKeyword)) {
            removeConfigItem('SpamKeywordsOpenInPost', spamKeyword);
        } else {
            addConfigItem('SpamKeywordsOpenInPost', spamKeyword);
        }
        Keyword.showSpamKeywordsWicket();
    },
    hideWhiteKeywordsWicket() {
        $('#white-keywords-wrap').hide();
        $('#show-white-keywords-btn').text('查看白名单');
        Keyword.hasRenderWhiteKeywordsWicket = false;
    },
    showWhiteKeywordsWicket() {
        refreshConfigItems('WhiteKeywords');
        refreshConfigItems('WhiteKeywordsCloseInPost');
        Keyword.renderWhiteKeywordsWicket();
        $('#spam-keywords-wrap').hide();
        $('#show-spam-keywords-btn').text('查看屏蔽词');
        $('#white-keywords-wrap').show();
        $('#show-white-keywords-btn').text('隐藏白名单');
        Keyword.hasRenderWhiteKeywordsWicket = true;
        Keyword.hasRenderSpamKeywordsWicket = false;
    },
    switchWhiteKeywordsWicket() {
        if (Keyword.hasRenderWhiteKeywordsWicket) {
            Keyword.hideWhiteKeywordsWicket();
        } else {
            Keyword.showWhiteKeywordsWicket();
        }
    },
    hideSpamKeywordsWicket() {
        $('#spam-keywords-wrap').hide();
        $('#show-spam-keywords-btn').text('查看屏蔽词');
        Keyword.hasRenderSpamKeywordsWicket = false;
    },
    showSpamKeywordsWicket() {
        refreshConfigItems('SpamKeywords');
        refreshConfigItems('SpamKeywordsOpenInPost');
        Keyword.renderSpamKeywordsWicket();
        $('#white-keywords-wrap').hide();
        $('#show-white-keywords-btn').text('查看白名单');
        $('#spam-keywords-wrap').show();
        $('#show-spam-keywords-btn').text('隐藏屏蔽词');
        Keyword.hasRenderSpamKeywordsWicket = true;
        Keyword.hasRenderWhiteKeywordsWicket = false;
    },
    switchSpamKeywordsWicket() {
        if (Keyword.hasRenderSpamKeywordsWicket) {
            Keyword.hideSpamKeywordsWicket();
        } else {
            Keyword.showSpamKeywordsWicket();
        }
    },
    preHighlightKeyword() {
        if ($('#keywords-highlighted-switch').text() == '贴内高亮') {
            Keyword.switchKeywordsHighlighted();
        }
        let scrollTop = $(document).scrollTop();
        let nodes = $('.highlight-keyword').toArray();
        for (let i = nodes.length - 1; i >= 0; i--) {
            let node = nodes[i];
            let nodeTop = $(node).parents('tr').parents('tr').prev().offset().top;
            if (nodeTop < scrollTop) {
                scrollTo(nodeTop);
                return;
            }
        }
    },
    nextHighlightKeyword() {
        if ($('#keywords-highlighted-switch').text() == '贴内高亮') {
            $('#keywords-highlighted-switch').click();
        }
        let scrollTop = $(document).scrollTop();
        let nodes = $('.highlight-keyword').toArray();
        for (let node of nodes) {
            let nodeTop = $(node).parents('tr').parents('tr').prev().offset().top;
            if (nodeTop - scrollTop > window.innerHeight) {
                $('html, body').animate({ scrollTop: nodeTop }, 1000);
                return;
            }
        }
    },
    addSpamPost(node) {
        let id = $(node).attr('id');
        $('#boardtr_' + id).remove();
        addConfigItem('SpamPosts', id);
    },
    eventRegister() {
        $(document).on('click', '.delete-white-keyword-btn', function() {
            Keyword.deleteWhiteKeyword(this);
        });
        $(document).on('click', '.delete-spam-keyword-btn', function() {
            Keyword.deleteSpamKeyword(this);
        });
        $(document).on('click', '.switch-white-keyword-in-post-btn', function() {
            Keyword.switchWhiteKeywordInPost(this);
        });
        $(document).on('click', '.switch-spam-keyword-in-post-btn', function() {
            Keyword.switchSpamKeywordInPost(this);
        });
        $(document).on('click', '.add-spam-post-btn', function() {
            Keyword.addSpamPost(this);
        });
    }
};

var Reply = {
    init() {
        Reply.autoFill();
        Reply.eventRegister();
    },
    autoFill() {
        $('input[name="username"]').val(getConfig('Username') || '= =');
        $('#selecthead').next().find('td').eq(0).append('<br /><a href="javascript:void(0);" id="resume-reply">恢复上次输入</a>');
    },
    eventRegister() {
        $(document).on('click', '#resume-reply', function() {
            $('textarea[name="body"]').val(getPostConfig('Reply') || '');
        });
        $('input[name="username"]').bind('input propertychange', function() {
            setConfig('Username', $('input[name="username"]').val());
        });
        $('textarea[name="body"]').bind('input propertychange', function() {
            let replyBody = $('textarea[name="body"]').val();
            let replyQuote = $('textarea[name="quote"]').val();
            replyBody = replyBody.replace(/<img\ssrc="(.*?)"\s(.*?=".*?")*?\s{0,1}\/{0,1}>/g, '<img src="$1">').replace(/<font color="#999999">(.*?)<\/font>/g, '$1');
            replyQuote = replyQuote.replace(/<img\ssrc="(.*?)"\s(.*?=".*?")*?\s{0,1}\/{0,1}>/g, '<img src="$1">').replace(/<font color="#999999">(.*?)<\/font>/g, '$1');
            $('textarea[name="body"]').val(replyBody);
            $('textarea[name="quote"]').val(replyQuote);
        });

    }
};

Style.initBeforeLoading();

$(function() {
    if (IS_BOARD_PAGE) {
        Style.init();
        Toolbar.init();
        Keyword.init();
    } else if (IS_POST_PAGE) {
        Style.init();
        Toolbar.init();
        Img.init();
        Landlord.init();
        Floor.init();
        Keyword.init();
        Reply.init();
    } else if (IS_SEARCH_PAGE) {
        Style.init();
    }

    window.onbeforeunload = function() {
        if (!getPostConfig('Floor')) {
            let currentFloor = Floor.getCurrentFloor();
            if (currentFloor > 10 && (currentFloor - 1) % 300 < 290) {
                setPostConfig('Floor', currentFloor);
            }
        }
        let reply = $('textarea[name="body"]').val();
        if (reply) {
            setPostConfig('Reply', reply);
        }
    };
});

function getConfig(name, defaultValue) {
    return localStorage.getItem(name) || defaultValue || '';
}

function setConfig(name, value) {
    localStorage.setItem(name, value);
}

function deleteConfig(name) {
    localStorage.removeItem(name);
}

function getPostConfig(name, defaultValue) {
    return getConfig(PREFIX + '_' + name, defaultValue);
}

function setPostConfig(name, value) {
    setConfig(PREFIX + '_' + name, value);
}

function deletePostConfig(name) {
    deleteConfig(PREFIX + '_' + name);
}

function getConfigItems(name) {
    let config = getConfig(name);
    return config ? config.split(SEPARATOR) : [];
}

function hasConfigItem(name, item) {
    return getConfigItems(name).indexOf(item) >= 0;
}

function addConfigItem(name, item) {
    localStorage.setItem(name, (getConfig(name) + SEPARATOR + item).trim());
}

function removeConfigItem(name, item) {
    localStorage.setItem(name, getConfig(name).replace(item, '').trim().replace(SEPARATOR + SEPARATOR, SEPARATOR));
}

function refreshConfigItems(name) {
    let items = Array.from(new Set(getConfigItems(name)));
    setConfig(name, items.join(SEPARATOR));
}

function getParamValue(key, url) {
    let query = url ? url.split('?')[1] : location.search.substring(1);
    let params = query.split('&');
    for (let param of params) {
        let pair = param.split('=');
        if (pair[0] === key) {
            return pair[1];
        }
    }
    return('');
}

function scrollTo(height) {
    $('html, body').animate({ scrollTop: height }, 1000);
}

function jumpToPost() {
    let postId = $('#post-id-jump-input').val().trim().replace(/\s+/g, SEPARATOR);
    if (postId === '') {
        alert('请输入要跳转的贴子ID!');
        return;
    }
    $('#post-id-jump-input').val('');
    window.open(`https://bbs.jjwxc.net/showmsg.php?board=${BOARD_ID}&id=${postId}`);
}

function countPeople() {
    let peopleIds = new Set();
    let i = 0;
    let callbackFn = function(data, textStatus, jqxhr) {
        if (textStatus == "success") {
            let peopleStrs = data.match(new RegExp('<font color=#999999>.*?</font>', 'g'));
            if (peopleStrs) {
                $.each(peopleStrs, function(i, s) {
                    peopleIds.add(s.replace('<font color=#999999>', '').replace('</font>', ''));
                });
                console.log(`第${i + 1}次统计,人数为${peopleIds.size}`);
            }
            if (i++ == PAGE_ID) {
                alert(`截至第${parseInt(PAGE_ID) + 1}页,该贴人数为${peopleIds.size}`);
            }
        }
    };
    for (let currentPageId = 0; currentPageId <= PAGE_ID; currentPageId++) {
        $.ajax({
            type: 'GET',
            url: `https://bbs.jjwxc.net/showmsg.php?board=${BOARD_ID}&id=${POST_ID}&page=${currentPageId}`,
            xhrFields: {
                withCredentials: true
            },
            success: callbackFn
        });
    }
}