Greasy Fork

Greasy Fork is available in English.

Forum Master・Discuz! Revision

Forum Master - Discuz! Beautify the interface, Remove ads, Enhance functions.

当前为 2024-11-03 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Forum Master・Discuz! Revision
// @name:en      Forum Master・Discuz! Revision
// @name:zh-CN   论坛大师・Discuz!修改版
// @name:zh-TW   論壇大師・Discuz!修改版
// @namespace    Forum Master・Discuz!-mxdh (Update by wwwab)
// @version      1.3.0
// @icon         https://discuz.dismall.com/favicon.ico
// @description  Forum Master - Discuz! Beautify the interface, Remove ads, Enhance functions.
// @description:en    Forum Master - Discuz! Beautify the interface, Remove ads, Enhance functions.
// @description:zh-CN 论坛大师(简体中文)・Discuz! 界面美化、移除广告、功能增强……
// @description:zh-TW 論壇大師(繁體中文)・Discuz! 界面美化、移除廣告、功能增強……
// @author       hostname,mxdh,wwwab
// @match        https://www.dismall.com/*
// @match        https://www.52pojie.cn/*
// @match        https://www.right.com.cn/forum/*
// @match        https://bbs.kafan.cn/*
// @match        https://hostloc.com/*
// @match        https://www.hostloc.com/*
// @match        https://bbs.pcbeta.com/*
// @match        https://bbs.huorong.cn/*
// @match        https://bbs.360.cn/*
// @match        https://iya.app/*
// @match        https://www.dospy.wang/*
// @match        https://www.aihao.cc/*
// @match        https://club.excelhome.net/*
// @match        https://bbs.3dmgame.com/*
// @match        https://home.x64bbs.cn/*
// @grant        unsafeWindow
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_log
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @license GPL-3.0
// ==/UserScript==

(function () {
    'use strict';

    //This is the original author's statement:
    /**
     * Forum Master・Discuz! - http://greasyfork.icu/scripts/400250
     *
     * == BEGIN LICENSE ==
     *
     * Open name: Forum Master・Discuz!
     * Open home: http://greasyfork.icu/scripts/400250
     *
     * Licensed under the terms of any of the following licenses at your
     * choice:
     *
     * 1. GPL - GNU General Public License
     *    https://www.gnu.org/licenses/gpl-3.0.html
     *
     * 2. MPL - Mozilla Public License
     *    https://www.mozilla.org/MPL/2.0/
     *
     * Copyright statement is prohibited from modification and must be retained.
     *
     * == END LICENSE ==
     */

    // Global Settings · Start
    const GLOBAL_CONFIG = {

        // Posts' sortord: 'unlocked', 'lastpost', 'threadcreate'(author dateline)
        // 主题帖排序方式: 'unlocked, 'lastpost', 'threadcreate'(author dateline)
        // 主題帖排序方式: 'unlocked, 'lastpost', 'threadcreate'(author dateline)
        thread_sortord: 'unlocked',

        // Lock the skin style: true/false
        // 固定皮肤样式: true/false
        // 固定皮膚樣式: true/false
        lock_skin: false,

        // Clean posts' format: true/false
        // 清除帖子格式: true/false
        // 清除帖子格式: true/false
        clean_post: false,

        // Display the users' online status: 'None', 'Standard', 'Advanced'
        // 显示用户的在线状态: 'None', 'Standard', 'Advanced'
        // 顯示用戶的在線狀態: 'None', 'Standard', 'Advanced'
        detection_mode: 'Advanced',

        // 小圆点(Small Dot): 'mode1'
        // Emoji or 文本(Text): 'mode2'
        standard_mode_detection_display_style: 'mode1',
        advanced_mode_detection_display_style: 'mode2',

        // Text Beautification: true/false
        // 文本美化: true/false
        // 文字美化: true/false
        text_beautification: true,

        // Code Beautification: true/false
        // 代码美化:true/false
        // 程式碼美化:true/false
        code_beautification: true,

        // Block Baidu_tongji code: true/false
        // 屏蔽百度统计: true/false
        // 屏蔽百度統計: true/false
        block_baidu_hm: true,

        // Bypass the word limit of reply: true/false
        // 回帖字数限制绕过: true/false
        // 回帖字數限制繞過: true/false
        word_count_limit_bypass: true,

        // Add a tail automatically at the end of the reply: true/false; Tail content: Text
        // 回帖小尾巴: true/false;回帖小尾巴内容: Text
        // 回帖小尾巴: true/false;回帖小尾巴內容: Text
        reply_tail: false,
        reply_tail_content: '  喵~',

        // Scene Mode: 'Standard', 'Family', 'Office'
        // 场景模式: 'Standard', 'Family', 'Office'
        // 場景模式: 'Standard', 'Family', 'Office'
        scene_mode: 'Standard',

        // Automatically refresh after modifying settings on webpage: true/false,
        // 在网页上修改设置后自动刷新: true/false,
        // 在網頁上修改設置後自動刷新: true/false,
        auto_reload: true,

        // Display Eomji: true/false
        // 显示Emoji: true/false
        // 顯示Emoji: true/false
        display_emoji: true,

    }
    // Global Settings · End

    // Below is the core code

    // Host Name
    const hn = window.location.hostname;

    // Path Name ("/<.<")
    const pn = window.location.pathname;
    // Search Name ("?*)
    const sn = window.location.search;

    function get_page_type() {
        const forum_page_regex_pn = /^\/forum-.*\.html$/;
        const forum_page_regex_sn = /^\?.*forumdisplay.*$/;
        const thread_page_regex_pn1 = /^\/thread-.*\.html$/;
        const thread_page_regex_pn2 = /^\/viewthread-.*\.html$/;
        const thread_page_regex_sn = /^\?.*viewthread.*$/;
        if (forum_page_regex_pn.test(pn) || forum_page_regex_sn.test(sn)) {
            return 'forum page';
        }
        if (thread_page_regex_pn1.test(pn) || thread_page_regex_pn2.test(pn) || thread_page_regex_sn.test(sn)) {
            return 'thread page';
        }
    }
    const page_type = get_page_type();

    function get_site_pos() {
        if (!!~hn.indexOf('.com.cn')) return -3;
        return -2;
    }

    const site_pos = get_site_pos();
    const site = hn.split('.').slice(site_pos, site_pos + 1).join().toUpperCase();

    GM_log("Site name:", site);

    // Scene mode: Standard, Family, Office
    var scene_mode = GM_getValue(site + '_SCENE_MODE') || GLOBAL_CONFIG.scene_mode;

    // Display the users online status
    var detection_mode = GM_getValue(site + '_DETECTION_MODE') || GLOBAL_CONFIG.detection_mode;

    // Clean posts' format
    var clean_post = GM_getValue(site + '_CLEAN_POST') || GLOBAL_CONFIG.clean_post;

    var lock_skin = GM_getValue(site + '_LOCK_SKIN') || GLOBAL_CONFIG.lock_skin;

    var thread_sortord = GM_getValue(site + '_THREAD_SORTORD') || GLOBAL_CONFIG.thread_sortord;

    // Test code
    const ua = window.navigator.userAgent;
    GM_log('User-Agent:', ua);
    GM_log('');

    GM_log('Scene mode:', scene_mode);
    GM_log(typeof scene_mode);
    GM_log('Detection mode:', detection_mode);
    GM_log(typeof detection_mode);
    GM_log('');

    const thread_sortord_dic = {
        unlocked: '未锁定',
        lastpost: '最后回复时间', 
        threadcreate: '发帖时间'
    }

    const thread_sortord_cutover_dic = {
        unlocked: 'lastpost',
        lastpost: 'threadcreate',
        threadcreate: 'unlocked'
    }

    const lock_skin_dic = {
        false: '关闭',
        true: '开启'
    }
    const lock_skin_cutover_dic = {
        false: true,
        true: false
    }

    const clean_post_dic = {
        false: '关闭',
        true: '开启'
    }

    const clean_post_cutover_dic = {
        false: true,
        true: false
    }

    const detection_mode_dic = {
        None: '关闭',
        Standard: '普通',
        Advanced: '高级'
    }

    const detection_mode_cutover_dic = {
        None: 'Standard',
        Standard: 'Advanced',
        Advanced: 'None'
    }

    const scene_mode_dic = {
        Standard: '标准模式',
        Family: '家庭模式',
        Office: '办公模式'
    }

    const scene_mode_cutover_dic = {
        Standard: 'Family',
        Family: 'Office',
        Office: 'Standard'
    }

    // Cascading Style Sheets・Global
    GM_addStyle(`
        :root {
            --blue: #007bff;
            --indigo: #6610f2;
            --purple: #6f42c1;
            --pink: #e83e8c;
            --red: #dc3545;
            --orange: #fd7e14;
            --yellow: #ffc107;
            --green: #28a745;
            --teal: #20c997;
            --cyan: #17a2b8;
            --white: #fff;
            --gray: #6c757d;
            --gray-dark: #343a40;
            --primary: #007bff;
            --secondary: #6c757d;
            --success: #28a745;
            --info: #17a2b8;
            --warning: #ffc107;
            --danger: #dc3545;
            --light: #f8f9fa;
            --dark: #343a40;
            --breakpoint-xs: 0;
            --breakpoint-sm: 576px;
            --breakpoint-md: 768px;
            --breakpoint-lg: 992px;
            --breakpoint-xl: 1200px;
            --font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans CJK", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei New", "Microsoft Yahei", "WenQuanYi Micro Hei", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
            --font-family-monospace: "Fira Code", Hack, "Source Code Pro", "Source Code Variable", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", "Noto Sans Mono CJK", "Microsoft YaHei Mono", "WenQuanYi Zen Hei Mono", monospace;
        }

        .ads,
        .plc .dnch_eo_pt,
        .plc .dnch_eo_pb,
        #diynavtop,
        #drk_colee_left1,
        #drk_colee_left2,
        #drk_ledtd,
        #hd .wp .a_mu,
        table .a_pr,
        .ad .plc .a_p,
        .a_h,
        .a_t,
        .a_pt,
        .a_pb {
            display: none;
        }

        .pls .avatar {
            padding-top: 1px;
            position: relative;
            text-align: center;
            object-fit: contain;
        }

        .pls .avatar img {
            width: 120px;
            height: 120px;
            object-fit: contain;
            background: none;
            border-radius: 50%;
            padding: 0;
            border: 2px solid #fff;
            box-shadow: 0 0 10px #00BFFF;
        }

        .pls .m img {
            width: 120px;
            height: 120px;
            object-fit: contain;
            border-radius: 50%;
            background: none;
        }

        .pls .m img:hover {
            background: #fff;
            object-fit: contain;
            background: #fff;
            border-radius: 0;
        }

        .avt img,
        #tath img,
        .rate table img,
        .cm .vm img,
        .card_mn .avt img {
            border: 2px solid #fff;
            border-radius: 50%;
            box-shadow: 0 0 2px #bbb;
        }

        .avt img:hover,
        #tath img:hover,
        .rate table img:hover,
        .cm .vm img:hover,
        .card_mn .avt img:hover {
            border-radius: 0;
            box-shadow: none;
        }

        .pls .avatar img,
        .avtm img,
        .avt img,
        #tath img,
        .rate table img,
        .cm .vm img,
        .card_mn .avt img,
        .pls .m img {
            -webkit-transition: 0.5s;
            -moz-transition: 0.5s;
            -ms-transition: 0.5s;
            -o-transition: 0.5s;
            transition: 0.5s;
        }

        .pls .avatar img:hover,
        .avt img:hover,
        #tath img:hover,
        .rate table img:hover,
        .cm .vm img:hover,
        .card_mn .avt img:hover {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
        }

        .user-online-status {
            display: block;
            margin: 0;
            border-collapse: collapse;
            text-align: center;
            position: absolute;
            left: 0;
            top: 0;
            width: 10px;
            height: 10px;
            cursor: help;
        }

        .user-status-expression {
            display: block;
            position: absolute;
            left: 0;
            top: 0;
            margin: 0;
            padding: 0;
            text-align: center;
            border-collapse: collapse;
            cursor: help;
        }

        .user-status-expression-online::after {
            content: '🌝';
        }

        .user-status-expression-offline::after {
            content: '🌚';
        }

        .offline {
            -webkit-filter: grayscale(100%);
            -moz-filter: grayscale(100%);
            -ms-filter: grayscale(100%);
            -o-filter: grayscale(100%);
            filter: grayscale(100%);
        }

        #hd .wp,
        #um {
            padding-top: 0;
        }

        .function-buttons {
            padding: 0 0 4px 0;
            text-align: right;
            white-space: nowrap;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        .custom-function-button {
            margin: 4px 4px;
            padding: 2px 8px;
            background-color: #FFFFFF;
            text-align: center;
            border:#DCDCDC solid 1px;
            border-radius: 4px;
            outline: none;
            cursor: pointer;
            font-weight: bold;
        }

        .custom-function-button:hover {
            box-shadow: 0 1px 2px #bbb;
            border-top: #00BFFF solid 1px;
            background-color: #F0FFFF;
        }

        .button-disabled {
            color: #808080;
            cursor: default;
        }

        .button-disabled:hover {
            box-shadow: none;
        }
    `);

    if (GLOBAL_CONFIG.text_beautification) {
        GM_addStyle(`
            body, table, input, button, select, textarea, a {
                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei New", "Microsoft Yahei", "WenQuanYi Micro Hei", "Noto Sans CJK", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
            }
        `)
    }

    if (GLOBAL_CONFIG.code_beautification) {
        GM_addStyle(`
            .mono, .md, .code, .pre, .tt, mono, md, code, pre, tt,
            .blockcode ol li {
                font-family: "Fira Code", Hack, "Source Code Pro", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", "Microsoft YaHei Mono", "WenQuanYi Zen Hei Mono", "Noto Sans Mono CJK", monospace !important;
            }
        `)
    }

    if (clean_post) {
        GM_addStyle(`
            .t_f font{
                font-size:inherit !important;
                color:inherit !important;
                background-color:inherit !important;
                font-family:inherit !important;
            }
            .t_f u{
                text-decoration:inherit !important;
            }
            .t_f strong{
                font-weight:inherit !important;
            }
            .t_f i{
                font-style:inherit !important;
            }
            .plhin {
                background: none !important;
            }
        `)
    }

    // Login status
    const member = !!document.getElementById('extcreditmenu') || !!document.getElementById('myprompt') || !!document.getElementById('myrepeats');

    GM_log('Login status:', member);
    GM_log('');

    // Default avatar
    function default_avatar() {
        if (site === '52POJIE') {
            GM_addStyle(`
                .pls .avatar img,
                .avtm img {
                    content: url('//avatar.52pojie.cn/images/noavatar_middle.gif');
                }

                #um .avt img,
                #tath img,
                .rate table img,
                .cm .vm img,
                .card_mn .avt img {
                    content: url('//avatar.52pojie.cn/images/noavatar_small.gif');
                }
            `);
        } else {
            GM_addStyle(`
                .pls .avatar img,
                .avtm img {
                    content: url('//uc.huorong.cn/images/noavatar_middle.gif');
                }

                #um .avt img,
                #tath img,
                .rate table img,
                .cm .vm img,
                .card_mn .avt img {
                    content: url('//uc.huorong.cn/images/noavatar_small.gif');
                }
            `);
        }
    }

    // Default avatar for Family attach
    function default_avatar_for_family_attach() {
        GM_addStyle(`
            .pls .avatar img:hover,
            .avtm img:hover,
            .avt img:hover,
            #tath img:hover,
            .rate table img:hover,
            .cm .vm img:hover,
            .card_mn .avt img:hover,
            .pls .m img {
                content: none;
            }
        `);
    }

    // Simplified avatar
    function simplified_avatar() {
        GM_addStyle(`
            .pls .avatar {
                margin: 10px auto;
                width: 60px;
                height: 60px;
            }

            .pls .avatar img {
                width: 60px;
                height: 60px;
            }

            .pls .avatar img:hover {
                border-radius: 0;
            }

            .md_ctrl,
            p.xg1,
            nav.toc,
            .scbar_hot_td,
            .pls .avatar_p .vm,
            img.authicn.vm,
            fieldset {
                display: none;
            }

            .plhin {
                background: none !important;
            }
        `);
    }

    // Hidden Signature
    function hidden_signature() {
        GM_addStyle(`
            .sign,
            .signature {
                display: none;
            }
        `);
    }


    // Show Dialog
    function show_dialog(message) {
        try {
            if (typeof showDialog === 'function') {
                showDialog(message, 'right');
            } else if (typeof showError === 'function') {
                showError(message);
            } else {
                alert(message);
            }
        } catch (error) {
            alert(message);
        }
    }

    // Scene mode
    switch (scene_mode) {
        case 'Standard':
            break;

        case 'Family':
            // Set as Default avatar
            default_avatar();
            // Set as Default avatar for Family attach
            default_avatar_for_family_attach();
            break;

        case 'Office':
            // Set as Default avatar
            default_avatar();
            // Set as Simplified avatar
            simplified_avatar();
            // Set as Hidden Signature
            hidden_signature();
            break;

        default:
            break;
    }

    // Display the user real online status
    function display_user_real_online_status(avatar, id) {
        let request = new XMLHttpRequest();
        let url = './home.php?mod=spacecp&ac=pm&op=showmsg&touid=' + id + '&inajax=1';
        request.open('GET', url);
        request.send();
        request.addEventListener('readystatechange', function () {
            if (this.readyState === 4 && this.status === 200) {
                let status = !!~this.response.indexOf('[在线]');
                let span = document.createElement('span');
                if (GLOBAL_CONFIG.advanced_mode_detection_display_style === 'mode2') {
                    span.className = status ? 'user-status-expression user-status-expression-online' : 'user-status-expression user-status-expression-offline';
                } else {
                    span.className = status ? 'user-online-status online gol' : 'user-online-status offline gol';
                }
                span.title = status ? '当前在线' : '当前离线';
                avatar.appendChild(span);
            }
        }, false);
    }

    // Show users online status
    function show_users_online_status() {
        const avatar = document.getElementsByClassName('avatar');
        const info = document.getElementsByClassName('i');
        const wait = site === 'PCBETA' ? 3000 : 1111;

        switch (detection_mode) {
            case 'None':
                break;

            case 'Standard':
                // Show default users online status
                for (let i = 0; i < info.length; i++) {
                    if (!!~info[i].innerHTML.indexOf('<em>当前在线</em>')) {
                        let div = document.createElement('div');
                        if (GLOBAL_CONFIG.standard_mode_detection_display_style === 'mode1') {
                            div.className = 'user-online-status online gol';
                        } else {
                            div.className = 'user-status-expression user-status-expression-online'
                        }
                        div.title = '当前在线';
                        avatar[i].appendChild(div);
                    } else {
                        let div = document.createElement('div');
                        if (GLOBAL_CONFIG.standard_mode_detection_display_style === 'mode1') {
                            div.className = 'user-online-status offline gol';
                        } else {
                            div.className = 'user-status-expression user-status-expression-offline'
                        }
                        div.title = '当前离线';
                        avatar[i].appendChild(div);

                        // avatar[i].classList.add('offline');
                    }
                }
                break;

            case 'Advanced':
                // Show real users online status
                for (let i = 0; i < info.length; i++) {
                    setTimeout(() => {
                        let html = avatar[i].innerHTML;
                        let id = /\d/.test(html) ? html.match(/\d+/)[0] : info[i].innerHTML.match(/\d+/)[0];
                        display_user_real_online_status(avatar[i], id);
                    }, i * wait + 1000);
                }
                break;

            default:
                break;
        }
    }

    // Execution as Show users online status
    if ((member) && (page_type === 'thread page')) {
        show_users_online_status();
    } else if ((site === 'PCBETA' || site === 'DOSPY' || site === '17500') && (page_type === 'thread page')) {
        detection_mode = 'Standard';
        show_users_online_status();
    }

    var display_check_in_button = true;
    var display_lock_skin_button = false;

    if (member && (site === 'KAFAN')) {
        let imgElement = document.querySelector('#pper_a .qq_bind');
        if (imgElement) {
            let src = imgElement.src;
            if (src.includes('wb.png')) {
                GM_log('Check-in status: have been checked in.');
            } else if (src.includes('dk.png')) {
                imgElement.click();
                GM_log('Automatic Check-in: Successful Check-in.');
            }
            display_check_in_button = false;
        }
    }

    if (member && (site === '52POJIE')) {
        let link = document.querySelector('a[href*="home.php?mod=task&do=apply&id=2"]');
        if (link) {
            let imgElement = link.querySelector('.qq_bind')
            if (imgElement) {
                let src = imgElement.src;
                if (src.includes('wbs.png')) {
                    GM_log('Check-in status: have been checked in.');
                } else if (src.includes('qds.png')) {
                    imgElement.click();
                    GM_log('Automatic Check-in: Successful Check-in.');
                }
            }
        }
        display_check_in_button = false;
    }

    if (member && (site === 'X64BBS')) {
        let link = document.querySelector('a[href*="plugin.php?id=study_daily_attendance:daily_attendance"]');
        if (link) {
            let fontElement = Array.from(link.querySelectorAll('font')).find(font => 
                font.style.color === 'red' && font.textContent.includes('打卡签到')
            );
            if (fontElement) {
                GM_log('找到了"打卡签到"元素');
                fontElement.click();
                GM_log('Automatic Check-in: Successful Check-in.');
            }
        }
        display_check_in_button = false;
    }

    if (site === 'KAFAN') {
        display_lock_skin_button = true;
    }

    if (lock_skin) {
        if (site === 'KAFAN') {
            let cssLink1 = document.createElement('link');
            cssLink1.rel = 'stylesheet';
            cssLink1.type = 'text/css';
            cssLink1.href = 'https://bbs.kafan.cn/template/comeing_city/style/t13/style.css';
            document.head.appendChild(cssLink1);
            
            let cssLink2 = document.createElement('link');
            cssLink2.rel = 'stylesheet';
            cssLink2.type = 'text/css';
            cssLink2.href = 'https://a.kafan.cn/static/template/comeing_city/style/t13/style.css?b33';
            document.head.appendChild(cssLink2);
        }
    }

    switch (thread_sortord) {
        case 'unlocked':
            break;

        case 'lastpost':
            if (page_type === 'forum page') {
                if (!window.location.search.includes("filter=lastpost&orderby=lastpost")) {
                    const lastpost = document.querySelector('a[href*="filter=lastpost&orderby=lastpost"]');
                    window.location.href = lastpost;
                }
            }
            break;

        case 'threadcreate':
            if (page_type === 'forum page') {
                if (!window.location.search.includes("filter=author&orderby=dateline")) {
                    const threadcreate = document.querySelector('a[href*="filter=author&orderby=dateline"]');
                    window.location.href = threadcreate;
                }
            }
            break;

        default:
            break;
    }

    if (site === 'HUORONG' || site === 'DOSPY') display_check_in_button = false;

    // Create Button Group
    function create_button_group() {
        // Function buttons
        const function_buttons = document.createElement('div');
        function_buttons.id = 'function-buttons';
        function_buttons.className = 'function-buttons';
        let function_buttons_package;
        switch (true) {
            case !!document.getElementsByClassName('xm_header_top_ul').length:
                function_buttons_package = document.getElementsByClassName('xm_header_top_ul')[0];
                break;

            case !!document.getElementById('extcreditmenu'):
                function_buttons_package = document.getElementById('extcreditmenu').parentElement;
                break;

            case site === 'PCBETA' && !!document.getElementsByClassName('hdc').length:
                function_buttons_package = document.getElementsByClassName('hdc')[0];
                break;

            case !!document.getElementsByClassName('menu').length:
                function_buttons_package = document.getElementsByClassName('menu')[0];
                break;

            case !!document.getElementById('pt'):
                function_buttons_package = document.getElementById('pt');
                break;

            default:
                break;
        }

        if (!!function_buttons_package === false) {
            GM_log('No nodes');
            return false;
        }

        // Scene mode button
        function scene_mode_mouseenter() {
            scene_mode = GM_getValue(site + '_SCENE_MODE') || scene_mode;
            this.innerHTML = scene_mode_dic[scene_mode];
        }
        function scene_mode_switch() {
            this.disabled = true;
            this.classList.add('button-disabled');
            scene_mode = scene_mode_cutover_dic[scene_mode];
            this.innerHTML = scene_mode_dic[scene_mode];
            GM_setValue(site + '_SCENE_MODE', scene_mode);
            if (GLOBAL_CONFIG.auto_reload) {
                window.location.reload();
                return;
            }
            let message = '场景模式切换成功,刷新页面即可进入 <span style="color: var(--info);">' + scene_mode_dic[scene_mode] + '</span>。';
            show_dialog(message);
            this.disabled = false;
            this.classList.remove('button-disabled');
        }
        if (page_type === 'thread page') {
            const scene_mode_button = document.createElement('button');
            scene_mode_button.className = 'custom-function-button scene-mode-button';
            scene_mode_button.innerHTML = scene_mode_dic[scene_mode];
            scene_mode_button.addEventListener('mouseenter', scene_mode_mouseenter, false);
            scene_mode_button.addEventListener('click', scene_mode_switch, false);
            function_buttons.appendChild(scene_mode_button);
        }

        // Detection mode button
        function detection_mode_mouseenter() {
            detection_mode = GM_getValue(site + '_DETECTION_MODE') || detection_mode;
            this.innerHTML = '探测模式:' + detection_mode_dic[detection_mode];
        }
        function detection_mode_switch() {
            this.disabled = true;
            this.classList.add('button-disabled');
            detection_mode = detection_mode_cutover_dic[detection_mode];
            this.innerHTML = '探测模式:' + detection_mode_dic[detection_mode];
            GM_setValue(site + '_DETECTION_MODE', detection_mode);
            if (GLOBAL_CONFIG.auto_reload) {
                window.location.reload();
                return;
            }
            let message = '探测模式切换成功,刷新页面即可进入 <span style="color: var(--info);">' + detection_mode_dic[detection_mode] + '</span>。';
            show_dialog(message);
            this.classList.remove('button-disabled');
        }
        if ((member) && (page_type === 'thread page')) {
            const detection_mode_button = document.createElement('button');
            detection_mode_button.className = 'custom-function-button detection-mode-button';
            detection_mode_button.innerHTML = '探测模式:' + detection_mode_dic[detection_mode];
            detection_mode_button.addEventListener('mouseenter', detection_mode_mouseenter, false);
            detection_mode_button.addEventListener('click', detection_mode_switch, false);
            function_buttons.appendChild(detection_mode_button);
        }

        // Clean post button
        function clean_post_mouseenter() {
            clean_post = GM_getValue(site + '_CLEAN_POST') || clean_post;
            this.innerHTML = '清除格式:' + clean_post_dic[clean_post];
        }
        function clean_post_switch() {
            this.disabled = true;
            this.classList.add('button-disabled');
            clean_post = clean_post_cutover_dic[clean_post];
            this.innerHTML = '清除格式:' + clean_post_dic[clean_post];
            GM_setValue(site + '_CLEAN_POST', clean_post);
            if (GLOBAL_CONFIG.auto_reload) {
                window.location.reload();
                return;
            }
            let message = '清除格式模式切换成功,刷新页面即可进入 <span style="color: var(--info);">' + clean_post_dic[clean_post] + '</span>。';
            show_dialog(message);
            this.classList.remove('button-disabled');
        }
        if (page_type === 'thread page') {
            const clean_post_button = document.createElement('button');
            clean_post_button.className = 'custom-function-button clean-post-button';
            clean_post_button.innerHTML = '清除格式:' + clean_post_dic[clean_post];
            clean_post_button.addEventListener('mouseenter', clean_post_mouseenter, false);
            clean_post_button.addEventListener('click', clean_post_switch, false);
            function_buttons.appendChild(clean_post_button);
        }

        // Lock skin button
        function lock_skin_mouseenter() {
            lock_skin = GM_getValue(site + '_LOCK_SKIN') || lock_skin;
            this.innerHTML = '锁定样式:' + lock_skin_dic[lock_skin];
        }
        function lock_skin_switch() {
            this.disabled = true;
            this.classList.add('button-disabled');
            lock_skin = lock_skin_cutover_dic[lock_skin];
            this.innerHTML = '锁定样式:' + lock_skin_dic[lock_skin];
            GM_setValue(site + '_LOCK_SKIN', lock_skin);
            if (GLOBAL_CONFIG.auto_reload) {
                window.location.reload();
                return;
            }
            let message = '锁定样式模式切换成功,刷新页面即可进入 <span style="color: var(--info);">' + clean_post_dic[clean_post] + '</span>。';
            show_dialog(message);
            this.classList.remove('button-disabled');
        }
        if (display_lock_skin_button) {
            const lock_skin_button = document.createElement('button');
            lock_skin_button.className = 'custom-function-button lock-skin-button';
            lock_skin_button.innerHTML = '锁定样式:' + lock_skin_dic[lock_skin];
            lock_skin_button.addEventListener('mouseenter', lock_skin_mouseenter, false);
            lock_skin_button.addEventListener('click', lock_skin_switch, false);
            function_buttons.appendChild(lock_skin_button);
        }

        // Thread sortord button
        function thread_sortord_mouseenter() {
            lock_skin = GM_getValue(site + '_THREAD_SORTORD') || thread_sortord;
            this.innerHTML = '主题帖排序方式:' + thread_sortord_dic[thread_sortord];
        }
        function thread_sortord_switch() {
            this.disabled = true;
            this.classList.add('button-disabled');
            thread_sortord = thread_sortord_cutover_dic[thread_sortord];
            this.innerHTML = '主题帖排序方式:' + thread_sortord_dic[thread_sortord];
            GM_setValue(site + '_THREAD_SORTORD', thread_sortord);
            if (GLOBAL_CONFIG.auto_reload) {
                window.location.reload();
                return;
            }
            let message = '主题帖排序方式模式切换成功,刷新页面即可进入 <span style="color: var(--info);">' + clean_post_dic[clean_post] + '</span>。';
            show_dialog(message);
            this.classList.remove('button-disabled');
        }
        if (page_type === 'forum page') {
            const thread_sortord_button = document.createElement('button');
            thread_sortord_button.className = 'custom-function-button thread-sortord-button';
            thread_sortord_button.innerHTML = '主题帖排序方式:' + thread_sortord_dic[thread_sortord];
            thread_sortord_button.addEventListener('mouseenter', thread_sortord_mouseenter, false);
            thread_sortord_button.addEventListener('click', thread_sortord_switch, false);
            function_buttons.appendChild(thread_sortord_button);
        }

        // Check in
        if (member && display_check_in_button) {
            function check_in() {
                const check_in = document.getElementsByClassName('check-in')[0];
                check_in.innerHTML = '正在签到';
                check_in.disabled = true;
                check_in.classList.add('button-disabled');
                setTimeout(() => {
                    let message = '签到完成';
                    check_in.innerHTML = message;
                    show_dialog(message)
                }, 1234);

                if (site === 'PCBETA') {
                    window.open('//i.pcbeta.com/home.php?mod=task&do=apply&id=149');
                    return false;
                }
                if (site === '52POJIE') {
                    window.open('//www.52pojie.cn/home.php?mod=task&do=apply&id=2');
                    return false;
                }
                if (site === 'X64BBS') {
                    showWindow('study_daily_attendance', 'plugin.php?id=study_daily_attendance:daily_attendance&fhash=' + document.getElementsByName('formhash')[0].value);
                    return false
                }
                if (site === 'KAFAN') {
                    showWindow('dsu_amupper', 'plugin.php?id=dsu_amupper&ppersubmit=true&formhash=' + document.getElementsByName('formhash')[0].value);
                    return false;
                }

                for (let i = 0; i < 10; i++) {
                    setTimeout(() => {
                        let request = new XMLHttpRequest();
                        let space = './home.php?mod=task&do=apply&id='.concat(i);
                        request.open('get', space);
                        request.send();
                    }, i * 100);
                }

                if (site === 'HOSTLOC') {
                    for (let i = 0; i < 20; i++) {
                        setTimeout(() => {
                            let request = new XMLHttpRequest();
                            let space = '//www.hostloc.com/space-uid-'.concat(Math.ceil(Math.random() * 47000 + 100), '.html');
                            request.open('get', space);
                            request.send();
                        }, i * 100 + 1000);
                    }
                }
            }
            const check_in_button = document.createElement('button');
            check_in_button.className = 'custom-function-button check-in';
            check_in_button.innerHTML = '每日签到';
            check_in_button.addEventListener('click', check_in, false);
            function_buttons.appendChild(check_in_button);
        }

        function_buttons_package.appendChild(function_buttons);
    }

    // Execution as Create Button Group
    create_button_group();

    // Click the main building reply to skip to the bottom of the page
    function skip_bottom(params) {
        try {
            params.removeAttribute('onclick');
            params.addEventListener('click', function (event) {
                params.href = 'javascript:;';
                window.scrollTo(0, 54321);
                let fastPostMessage = document.getElementById('fastpostmessage');
                !!fastPostMessage && fastPostMessage.focus();
            }, false);
        } catch (error) {
            GM_log('You don\'t have permission to post content.');
        }
    }
    if (document.getElementsByClassName('prev').length === 0) {
        const locked = member && document.getElementsByClassName('locked');
        if (typeof locked === 'object' && !!locked.length) {
            for (let i = 0; i < locked.length; i++) {
                skip_bottom(locked[i].getElementsByTagName('a')[0]);
            }
        }
        const fastre = member && document.getElementsByClassName('fastre')[0];
        !!fastre && skip_bottom(fastre);
        const replyfast = member && document.getElementsByClassName('replyfast')[0];
        !!fastre && skip_bottom(replyfast);
    }


// 回帖字数限制绕过 - (1)获取回帖字数不足时的填充内容 · Start
    function get_WordCountLimitBypass_Attach_Content() {
        switch (site) {
            case 'KAFAN':
                return '';
            case '52POJIE':
                return '';
            case 'HOSTLOC':
                return '󠀠'.repeat(10);
            default:
                return '\n\n[color=#ffffff]插入空白字符以填充字数[/color]'; // 默认为纯白色字体的"插入空白字符以填充字数"
        }
    }

    if (GLOBAL_CONFIG.word_count_limit_bypass) {
        var WordCountLimitBypass_AttachContent = get_WordCountLimitBypass_Attach_Content();
    } else {
        var WordCountLimitBypass_AttachContent = '';
    }
    // 回帖字数限制绕过 - (1)获取回帖字数不足时的填充文本 · End


    // 回帖字数限制绕过 - (2)字数填充函数 & 回帖小尾巴功能函数 · Start
    function editor_content(PostMessage) {
        let PostMessageContent = PostMessage.value;
        if (GLOBAL_CONFIG.word_count_limit_bypass && PostMessageContent) {
            if (GLOBAL_CONFIG.reply_tail) {
                PostMessageContent = PostMessageContent.trim();
                PostMessage.style.opacity = '0';
                if (PostMessageContent.length < 20) {
                    GM_log("editor_content_mode1")
                    PostMessage.value = PostMessageContent.concat(GLOBAL_CONFIG.reply_tail_content + WordCountLimitBypass_AttachContent);
                } else {
                    GM_log("editor_content_mode2")
                    PostMessage.value = PostMessageContent.concat(GLOBAL_CONFIG.reply_tail_content);
                }
                setTimeout(() => {
                    PostMessage.value = PostMessageContent;
                    PostMessage.style.opacity = '1';
                }, 100);
            } else {
                if (PostMessageContent && PostMessageContent.length < 20) {
                    GM_log("editor_content_mode3")
                    PostMessageContent = PostMessageContent.trim();
                    PostMessage.style.opacity = '0';
                    PostMessage.value = PostMessageConten.concat(WordCountLimitBypass_AttachContent);
                    setTimeout(() => {
                        PostMessage.value = PostMessageContent;
                        PostMessage.style.opacity = '1';
                    }, 100);
                }
            }
        } else {
            if (GLOBAL_CONFIG.reply_tail && PostMessageContent) {
                GM_log("editor_content_mode4")
                PostMessageContent = PostMessageContent.trim();
                PostMessage.style.opacity = '0';
                PostMessage.value = PostMessageContent.concat(GLOBAL_CONFIG.reply_tail_content);
                setTimeout(() => {
                    PostMessage.value = PostMessageContent;
                    PostMessage.style.opacity = '1';
                }, 100);
            }
        }
    }


    // 回帖字数限制绕过 - (3)在主题帖最下方的快速回帖栏内字数不足时进行填充 · Start
    const fastPostMessage = document.getElementById('fastpostmessage');

    !!fastPostMessage && fastPostMessage.removeAttribute('onkeydown');

    !!fastPostMessage && fastPostMessage.addEventListener('keydown', function (event) {
        if (event.ctrlKey && event.which === 13) {
            editor_content(fastPostMessage);
            seditor_ctlent(event, 'fastpostvalidate($(\'fastpostform\'))');
        }
        if (event.altKey && event.which === 83) {
            editor_content(fastPostMessage);
            seditor_ctlent(event, 'fastpostvalidate($(\'fastpostform\'))');
        }
    }, false);

    const fastPostSubmit = document.getElementById('fastpostsubmit');
    !!fastPostSubmit && fastPostSubmit.addEventListener('click', () => {
        editor_content(fastPostMessage);
    }, false);
    // 回帖字数限制绕过 - (3)在主题帖最下方的快速回帖栏内字数不足时进行填充 · End


    // 回帖字数限制绕过 - (4)回复他人楼层时在"参与/回复主题"框内字数不足时进行填充 · Start
    function bindClicksToFastres() {
        const fastres = document.getElementsByClassName('fastre');
        Array.from(fastres).forEach((elem, index) => {
            if (index !== 0) {                                    // 跳过第一个元素,因为第一个元素已由上方skip_bottom()函数进行处理
                elem.removeEventListener('click', () => {         // 避免重复监听
                    handleFastreClick();
                }, false);
                elem.addEventListener('click', () => {
                    handleFastreClick();
                }, false);
            }
        });
    }
 
    // postSubmit.__eventBound属性用于确保对同一个postsubmit按钮的多次点击不会导致重复绑定事件监听器,避免了潜在的内存泄漏或其他问题。
    function handleFastreClick() {
        // 使用MutationObserver等待postmessage和postsubmit的出现
        const observer = new MutationObserver((mutations, obs) => {
            const postMessage = document.getElementById('postmessage');
            const postSubmit = document.getElementById('postsubmit');
            if (postMessage && postSubmit && !postSubmit.__eventBound) { // 检查postmessage和postsubmit是否存在,检查postSubmit是否已经绑定了事件监听器
                GM_log("Reply window has appeared."); // postmessage和postsubmit已出现
                postSubmit.__eventBound = true; // 标记postSubmit已经绑定了事件监听器
                postSubmit.addEventListener('click', () => {
                    GM_log('postsubmit被点击');
                    editor_content(postMessage);
                    ResetState();
                }, false);
                obs.disconnect(); // 断开观察者
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function ResetState() {
        // 重置监听状态,准备下一次点击
        const postSubmit = document.getElementById('postsubmit');
        if (postSubmit) {
            delete postSubmit.__eventBound; // 移除标记以允许再次监听
        }
    }
    
    bindClicksToFastres();
    // 回帖字数限制绕过 - (4)回复他人楼层时在"参与/回复主题"框内字数不足时进行填充 · End


    // 回帖字数限制绕过 - (5)在高级模式提交时获取字数检查并判断当前长度是否符合系统限制 · Start
    // 执行字数检查并判断当前长度是否符合系统限制
    function checkWordCount() {
        const checkButton = document.getElementById('e_chck');
        if (checkButton) {
            const postSubmit = document.getElementById('postsubmit');
            !!postSubmit && postSubmit.addEventListener('click', () => {
                checkButton.click();
                const alertContent = getAlertInfoContent();
                closeDialog();
                const currentLength = Number(getCount(alertContent).currentLength)
                const systemMinLimit = Number(getCount(alertContent).systemMinLimit)
                if (currentLength < systemMinLimit) {
                    show_dialog('检测到您输入的内容可能未达到系统字数限制,您可以增加字数或者复制"\n\n[color=#ffffff]插入空白字符以填充字数[/color]"到尾部以解决该问题')
                }
            }, false);
        }
    }
    // 获取字数检查内容
    function getAlertInfoContent() {
        const alertInfo = document.querySelector('.alert_info p');
        return alertInfo ? alertInfo.textContent : '';
    }
    // 关闭字数检查弹窗
    function closeDialog() {
        const closeButton = document.getElementById('fwin_dialog_close');
        if (closeButton) {
            closeButton.click();
        }
    }
    checkWordCount();

    function getCount(text) {
        const regex1 = /当前长度: (.*?) 字节/;
        const regex2 = /系统限制: (.*?) 到/;
        const regex3 = /到 (.*?) 字节/;
        const match1 = text.match(regex1);
        const match2 = text.match(regex2);
        const match3 = text.match(regex3);
        const currentLength = match1 ? match1[1] : null;
        const systemMinLimit = match2 ? match2[1] : null;
        const systemMaxLimit = match3 ? match3[1] : null;
        return { currentLength:currentLength, systemMinLimit:systemMinLimit, systemMaxLimit: systemMaxLimit}
    }
    // 回帖字数限制绕过 - (5)在高级模式提交时获取字数检查并判断当前长度是否符合系统限制 · End
    

    // Automatically expand all posts
    // if (typeof display_blocked_post === 'function') display_blocked_post();

    // Display Emoji
    if (GLOBAL_CONFIG.display_emoji) {
        const post = document.getElementsByClassName('t_f');
        for (let i = 0; i < post.length; i++) {
            post[i].innerHTML = post[i].innerHTML.replace(/\&amp;#.*?;/g, function (char) {
                if (char.length === 13) {
                    return String.fromCodePoint(parseInt(char.match(/[0-9]+/)));
                }
                return char;
            }
            );
        }
    }

    // Compatibility settings

    // Cascading Style Sheets・www.hostloc.com
    site === 'HOSTLOC' && GM_addStyle(`
        #hiddenpoststip {
            padding: 0;
        }

        #hiddenpoststip a {
            height: 32px;
            line-height: 32px;
            font-size: 16px;
        }

        #hiddenpoststip a:hover {
            color: #f33;
        }

        #hiddenpoststip a::before {
            padding-right: 8px;
            content: "🌜";
        }

        #hiddenpoststip a::after {
            padding-left: 8px;
            content: "🌛";
        }
    `);

    // Cascading Style Sheets・bbs.pcbeta.com
    site === 'PCBETA' && page_type === 'thread page' && GM_addStyle(`
            #wp > div:first-child  {
                display: none !important;
            }

            #wp > div,
            #nv_forum > span,
            .pls .tip,
            ignore_js_op .tip {
                display: none;
            }

            #wp > div.cl,
            #wp > div.wp,
            #nv_forum #scrolltop {
                display: block;
            }

            .pls .avatar {
                overflow: unset;
            }

            .pb_pls .avatar img {
                border-radius: 50%;
                background: none;
                -webkit-transition: 0.5s;
                -moz-transition: 0.5s;
                -ms-transition: 0.5s;
                -o-transition: 0.5s;
                transition: 0.5s;
            }

            .pb_pls .avatar img:hover {
                border-radius: 0;
            }

            .hdc {
                position: relative;
            }

            .function-buttons {
                position: absolute;
                right: 0;
                padding: 0 8px 4px 0;
            }

            .custom-function-button {
                margin: 0 4px;
            }

            .wp .pgs {
                -moz-user-select: none;
                -ms-user-select: none;
                -webkit-user-select: none;
                user-select: none;
            }
    `);
})();