NGA Likes Support

显示被点赞数量

2020/11/26のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name        NGA Likes Support
// @namespace   https://greasyfork.org/users/263018
// @version     1.0.2
// @author      snyssss
// @description 显示被点赞数量

// @match       *bbs.nga.cn/read.php?tid=*
// @match       *ngabbs.com/read.php?tid=*

// @noframes
// ==/UserScript==

(ui => {
    if (!ui) return;

    const hookFunction = (object, functionName, callback) => {
        (originalFunction => {
            object[functionName] = function() {
                const returnValue = originalFunction.apply(this, arguments);

                callback.apply(this, [returnValue, originalFunction, arguments]);

                return returnValue;
            };
        })(object[functionName]);
    };

    const viewLikes = (argid) => {
        const args = ui.postArg.data[argid];

        if (args.comment) return;

        const uid = +args.pAid;

        if (uid > 0) {
            fetch(`/nuke.php?__lib=ucp&__act=get&lite=js&uid=${uid}`)
                .then(res => res.text())
                .then(res => res.match(/{"type":8,"data":(\d+)}/))
                .then(res => res ? res[1] : 0)
                .then(res => {
                const anchor = ui.postArg.data[argid].uInfoC.querySelector('[name=uid]');

                const likes = document.createElement('SPAN');

                likes.className = 'small_colored_text_btn stxt block_txt_c2 vertmod';
                likes.innerHTML = `<span class="white"><span style="font-family: comm_glyphs; -webkit-font-smoothing: antialiased; line-height: 1em;">⯅</span>&nbsp;${res}</span>`;

                anchor.after(likes);
            });
        }
    }

    hookFunction(ui, 'postDisp', (returnValue, originalFunction, arguments) => viewLikes(arguments[0]));

    Object.keys(ui.postArg.data).forEach(i=> viewLikes(i));
})(commonui);