巴哈姆特調整檢視回覆留言

點開來才能看到回覆的訊息?不需要,只要將游標移上去就可以看到留言!

目前為 2022-08-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         巴哈姆特調整檢視回覆留言
// @version      0.2
// @description  點開來才能看到回覆的訊息?不需要,只要將游標移上去就可以看到留言!
// @author       Peugin_
// @namespace    https://home.gamer.com.tw/homeindex.php?owner=f31033103
// @match        https://forum.gamer.com.tw/C.php?*
// @match        https://forum.gamer.com.tw/Co.php?*
// @require      https://unpkg.com/popper.js@1
// @require      https://unpkg.com/tippy.js@5
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    function GM_addStyle(css) {
        const style = document.getElementById("GM_addStyleBy8626") || (function () {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.id = "GM_addStyleBy8626";
            document.head.appendChild(style);
            return style;
        })();
        const sheet = style.sheet;
        sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
    }

    GM_addStyle(".tippy-popper{max-width:none;}");

    (new MutationObserver(check)).observe(document, {childList: true, subtree: true});
    (new MutationObserver(checkMoreReply)).observe(document, {childList: true, subtree: true});

    function check(changes, observer) {
        if (document.querySelector('a[href^="javascript:Forum.C.openCommentDialog"]')) {
            observer.disconnect();
            document.querySelectorAll('a[href^="javascript:Forum.C.openCommentDialog"]').forEach(function (reply) {
                let bsn = reply.getAttribute("href").match(/\d+/g)[0];
                let snB = reply.getAttribute("href").match(/\d+/g)[1];
                let snC = reply.getAttribute("href").match(/\d+/g)[2];

                fetch(`https://api.gamer.com.tw/forum/v1/comment_get.php?bsn=${bsn}&snB=${snB}&snC=${snC}&type=pc`)
                    .then(res => {
                        return res.json();
                    })
                    .then(res => {
                        reply.setAttribute("data-placement", "top");
                        reply.setAttribute("data-toggle", "tooltip");
                        reply.setAttribute("data-tooltipped", "");
                        reply.setAttribute("href", "#");
                        reply.addEventListener("click",function(e){
                            e.preventDefault();
                        });
                        reply.setAttribute("data-tippy-content", `<div class="dialogify" style="display: contents; text-align:left;"><div class="dialogify__body">${res.data.comment.html}</div></div>`);
                        tippy(reply, {
                            maxWidth: 560,
                            interactive: true,
                            appendTo: document.body,
                            onShow(instance) { Forum.C.commentFormatter(instance.popper.querySelector("span"))}
                        });
                    })
            });
        }
    };

    function checkMoreReply(changes, observer) {
        if (document.querySelector('a[class="more-reply"]')) {
            observer.disconnect();
            document.querySelectorAll('a[class="more-reply"]').forEach(function (moreReply) {
                moreReply.addEventListener('click', function () {
                    (new MutationObserver(check)).observe(document, {
                        childList: true,
                        subtree: true
                    });
                })
            })
        }
    };
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址