Add Quality Score to C.AI

this userscript adds a 'quality' score to characters. it's based on the actions/likes ratio. this way you can be more informed when choosing a character to talk to

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Add Quality Score to C.AI
// @author      Redacted Basilisk
// @namespace   c.ai quality score
// @description this userscript adds a 'quality' score to characters. it's based on the actions/likes ratio. this way you can be more informed when choosing a character to talk to
// @match       https://beta.character.ai/*
// @version     1.0
// @license     GPLv3
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

window.onload = function() {
    (new MutationObserver(check)).observe(document, { childList: true, subtree: true });
};

const convertToNumber = str => (isNaN(parseFloat(str)) ? 1 : parseFloat(str)) * (str.endsWith('m') ? 1e6 : (str.endsWith('k') ? 1e3 : 1));
function check(changes, observer) {
    observer.disconnect();

  if(document.querySelector('.MuiToggleButtonGroup-root button[value="like"]')) {
        observer.disconnect();
        var likesCount = convertToNumber($('.MuiToggleButtonGroup-root button[value="like"] div').text());
        var actionsCount = convertToNumber($('[style="font-size: 12px; margin-left: 8px; font-weight: 400; display: flex; gap: 2px; align-items: center;"]').text());
        var result = Math.round(0.6*Math.log(actionsCount+1) / 1.2*Math.log(likesCount+1));
        var color = result < 18 ? "#b82f0d" : result < 28 ? "#ba8b0b" : "#258a00"; //change colors if you want. the order is red yellow green
        //console.log(likesCount, actionsCount);

        var lastButton = $('.MuiToggleButtonGroup-root[aria-label="Vote"]>button:last-child');
        lastButton.after('<div id="quality" style="color: ' + color + '!important; padding-top: 4px; padding-left: 8px;">' + result + '</div>');
    }

    observer.observe(document, { childList: true, attributes: true, characterData: true, subtree: true,  attributeFilter: ['class'] });
}