NGA Likes Support

显示被点赞数量

当前为 2020-11-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        NGA Likes Support
// @namespace   https://greasyfork.org/users/263018
// @version     1.0.0
// @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 uid = ui.postArg.data[argid].pAid;

        fetch(`/nuke.php?__lib=ucp&__act=get&lite=js&uid=${uid}`)
            .then(res => res.text())
            .then(res => res.match(/{"type":8,"data":(\d+)}/)[1])
            .then(res => {
            if (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);