NGA Likes Support

显示被点赞数量

目前為 2020-11-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);