flyink13 / vk apps manage: onclick members_count

// ==UserScript==
// @name         vk apps manage: onclick members_count
// @namespace    http://tampermonkey.net/
// @version      0.1
// @author       Flyink13
// @match        https://vk.com/apps?act=manage
// @resource     apiLib https://ifx.su/~va
// @grant        GM_getResourceText
// @copyright 2021, flyink13 (https://openuserjs.org/users/flyink13)
// @updateURL https://openuserjs.org/meta/flyink13/vk_apps_manage_onclick_members_count.meta.js
// @downloadURL https://openuserjs.org/install/flyink13/vk_apps_manage_onclick_members_count.user.js
// @license MIT
// ==/UserScript==

function main() {
    const declOfNum = (n, titles) => titles[n%10===1 && n%100!==11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2];
    
    document.querySelectorAll('.apps_settings_size').forEach((el) => {
        el.onclick = (event) => {
            const app_id = event.target.closest('._apps_settings_row').id.replace(/[^\d]/g, '');
            window.API('apps.get', { app_id }).then(({ response }) => {
                const { members_count } = response.items[0];
                el.textContent = Number(members_count).toLocaleString() + ' ' + declOfNum(members_count, ['участник', 'участника', 'участников']);
            })
        }
    });
}

(function injectScript() {
    var script = document.createElement('script');
    var code = '(' + main + ')();';
    code += '(function(){' + (GM_getResourceText('apiLib')) + '})();';
    script.appendChild(document.createTextNode(code));
    (document.body || document.head || document.documentElement).appendChild(script);
})();