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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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>`);
   }

})();