AO3: Score

'Engagement' score - it's calculated as follows: (Bookmarks + (Comments / Chapters)) / Kudos * 100, for works with a minimum of 1 bookmark and 6 kudos.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AO3: Score
// @namespace    https://codeberg.org/schegge
// @description  'Engagement' score - it's calculated as follows: (Bookmarks + (Comments / Chapters)) / Kudos * 100, for works with a minimum of 1 bookmark and 6 kudos.
// @version      1.0
// @author       Schegge
// @match        *://archiveofourown.org/*
// @match        *://www.archiveofourown.org/*
// ==/UserScript==

(function() {

   const SN = 'escore'

   const DATA = {
      levels: [ 40,        20,        10,        0],
      colors: ['#8E7DBE', '#A6D6D6', '#FFF1D5', '#F7CFD8']
   };

   document.head.insertAdjacentHTML('beforeend', `<style>
      dd.${SN} { color: #000 !important; padding-inline: .35em !important; border-radius: .5em; }
      dl.stats.${SN} .collections, dl.stats.${SN} .hits { display: none !important; }
   </style>`);

   function count(el, split = false) {
      let num = el.textContent.trim();
      if (split) num = num.split(split)[0];
      else num = num.replace(/,/g, '');
      return parseInt(num);
   }

	for (const work of document.querySelectorAll('dl.stats')) {
      const kudos = work.querySelector('dd.kudos');
      const bookmarks = work.querySelector('dd.bookmarks');
      const comments = work.querySelector('dd.comments');
      const chapters = work.querySelector('dd.chapters');

      if (!kudos || !bookmarks) continue;
      let ku = count(kudos);
      if (ku < 6) continue;

      work.classList.add(SN);

      let ch = count(chapters, '/');
      let co = comments ? count(comments) / ch : 0;

      const score = Math.round(100 * (count(bookmarks) + co) / ku);

      let color = '';
      for (const [index, level] of DATA.levels.entries()) {
         if (score > level) {
            color = DATA.colors[index];
            break;
         }
      }

      work.insertAdjacentHTML('beforeend',
         `<dt>Score:</dt> <dd class="${SN}" style="background-color: ${color}">${score}</dd>`);
   }

})();