Greasy Fork

Greasy Fork is available in English.

NGA 自动查成分

在 nga 的用户页上显示用户分别在哪些版面发言了多少次

当前为 2023-06-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        NGA 自动查成分
// @description 在 nga 的用户页上显示用户分别在哪些版面发言了多少次
// @license MIT
// @match       *://bbs.nga.cn/nuke.php*
// @match       *://nga.178.com/nuke.php*
// @match       *://ngabbs.com/nuke.php*
// @version     0.1
// @grant       none
// @namespace http://greasyfork.icu/users/1096435
// ==/UserScript==

const blobToBase64 = blob => new Promise(resolve => {
  const reader = new FileReader();
  reader.onloadend = () => resolve(reader.result);
  reader.readAsText(blob, 'GBK');
});
const wait = selector => new Promise(resolve => {
  const id = window.setInterval(() => {
    const dom = document.querySelector(selector);
    if (!dom) return;
    window.clearInterval(id);
    resolve();
  }, 100);
});
(async () => {
  await wait('#ucp_block > span');
  const dom = document.createElement('span');
  dom.innerHTML = `
    <h2 class=" catetitle">
      :: 成分 ::
      <img src="about:blank" style="display: none;">
    </h2>
    <div class=" cateblock" id="ucpuser_sign_blockContent" style="text-align: left; line-height: 1.8em;">
      <div class="contentBlock" style="padding: 5px 10px;">
        <span><div id="blood" style="margin: 0.25em 0px;"></div></span>
        <div class=" clear"></div>
      </div>
    </div>
  `;
  document.querySelector('#ucp_block > span').append(dom);
  const frequency = {};
  const show = () => {
    document.querySelector('#blood').innerHTML = Object.entries(frequency).sort(([, a], [, b]) => b - a).map(([name, num]) => `<p>${name}: ${num}</p>`).join('');
  };
  const params = new URLSearchParams(window.location.search);
  const aid = params.get('authorid') ?? params.get('uid');
  const work = async page => {
    const res = await fetch(`/thread.php?searchpost=1&authorid=${aid}${page ? `&page=${page}` : ''}`);
    const html = await blobToBase64(await res.blob());
    html.match(/(?<=\?fid=.+?['"] class=['"]silver['"]>\[).+?(?=\]<\/a>)/g)?.forEach(fname => {
      if (!Reflect.has(frequency, fname)) frequency[fname] = 1;else frequency[fname] += 1;
    });
    show();
    const nextPage = html.match(/(?<=page=)\d+(?=['"] title=['"]可能有下一页)/);
    if (nextPage?.[0]) return work(nextPage[0]);
  };
  work();
})();