Kanka Subpage Elements Counter

Shows the count of attributes, relations, assets, etc. on each entity's corresponding submenu item

目前為 2023-06-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Kanka Subpage Elements Counter
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      2
// @description  Shows the count of attributes, relations, assets, etc. on each entity's corresponding submenu item
// @author       Salvatos
// @match        https://kanka.io/*
// @icon         https://www.google.com/s2/favicons?domain=kanka.io
// @connect      kanka.io
// ==/UserScript==

// Get JSON export URL for the current entity
const exportLink = document.querySelector('a[href$="/json-export"]');
if (exportLink) {
    var apiURL = exportLink.href;

    // Request JSON for the target entity
    var xhr = new XMLHttpRequest();
    xhr.open("GET", apiURL, true);
    xhr.responseType = 'json';
    xhr.onload = function (e) {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                let abilities = xhr.response.data.entity_abilities.length,
                    attributes = xhr.response.data.attributes.length,
                    events = xhr.response.data.entity_events.length,
                    inventory = xhr.response.data.inventory.length,
                    elements = xhr.response.data.elements.length;

                // Abilities
                if (abilities > 0) {
                    document.querySelector('.entity-menu a[href$="/entity_abilities"]').insertAdjacentHTML("beforeend", `<div class="badge flex gap-2 items-center float-right">${abilities}</div>`);
                }
                // Attributes
                if (attributes > 0) {
                    document.querySelector('.entity-menu a[href$="/attributes"]').insertAdjacentHTML("beforeend", `<div class="badge flex gap-2 items-center float-right">${attributes}</div>`);
                }
                // Events/reminders
                if (events > 0) {
                    document.querySelector('.entity-menu a[href$="/entity_events"]').insertAdjacentHTML("beforeend", `<div class="badge flex gap-2 items-center float-right">${events}</div>`);
                }
                // Inventory
                if (inventory > 0) {
                    document.querySelector('.entity-menu a[href$="/inventory"]').insertAdjacentHTML("beforeend", `<div class="badge flex gap-2 items-center float-right">${inventory}</div>`);
                }
                // Quest elements (Kanka only shows elements that are entities, not "loose" ones)
                if (elements > 0) {
                    // If there’s already a count, update it instead of creating a new badge
                    if (document.querySelector('.entity-menu a[href$="/quest_elements"] .badge')) {
                        document.querySelector('.entity-menu a[href$="/quest_elements"] .badge').innerHTML = elements;
                    }
                    else {
                        document.querySelector('.entity-menu a[href$="/quest_elements"]').insertAdjacentHTML("beforeend", `<div class="badge flex gap-2 items-center float-right">${elements}</div>`);
                    }
                }
                // Assets are already handled by Kanka like child entities
                // Relations not provided (only pinned relations, which we can already see)

            } else {
                console.error(xhr.statusText);
            }
        }
    };
    xhr.onerror = function (e) {
        console.error(xhr.statusText);
    };
    xhr.send(null);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址