// ==UserScript== // @name NGA Likes Support // @namespace https://greasyfork.org/users/263018 // @version 1.0.1 // @author snyssss // @description 显示被点赞数量 // @match *bbs.nga.cn/read.php?tid=* // @match *ngabbs.com/read.php?tid=* // @noframes // @downloadURL none // ==/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) { 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 = ` ${res}`; anchor.after(likes); }); } } hookFunction(ui, 'postDisp', (returnValue, originalFunction, arguments) => viewLikes(arguments[0])); Object.keys(ui.postArg.data).forEach(i=> viewLikes(i)); })(commonui);