显示被点赞数量
当前为
// ==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> ${res}</span>`;
anchor.after(likes);
}
});
}
hookFunction(ui, 'postDisp', (returnValue, originalFunction, arguments) => viewLikes(arguments[0]));
Object.keys(ui.postArg.data).forEach(i=> viewLikes(i));
})(commonui);