// ==UserScript== // @name 知乎评论区显示momo/用户唯一ID // @namespace https://zhufn.fun // @license AGPL3 // @version 1.7 // @description 可配置显示所有用户id或只显示指定用户名(如momo)的。可切换使用人类可读id(需发送请求,可能有反爬,加了缓存)或一串16进制id。Hex id太长了默认会截断,可配置。 // @author zhufengning // @match https://www.zhihu.com/* // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @run-at document-end // @downloadURL none // ==/UserScript== (function() { 'use strict'; let targetName = GM_getValue('targetName', 'momo'); let showAllUsers = GM_getValue('showAllUsers', false); let fetchHumanReadable = GM_getValue('fetchHumanReadable', true); let userIdCache = GM_getValue('userIdCache', {}); let maxIdLength = GM_getValue('maxIdLength', 4); function saveUserIdCache() { GM_setValue('userIdCache', userIdCache); } function clearUserIdCache() { userIdCache = {}; GM_setValue('userIdCache', userIdCache); alert('已清除用户ID缓存'); } function fetchHumanReadableID(userId, callback) { if (!fetchHumanReadable) { callback(userId.substring(0, maxIdLength)); return; } if (userIdCache[userId]) { callback(userIdCache[userId]); return; } GM_xmlhttpRequest({ method: 'GET', url: `https://www.zhihu.com/people/${userId}`, onload: function(response) { try { const jsonMatch = response.responseText.match(/