[GC] - Enhanced Relic Log View

See additional details related to your relic log, included view filter options.

目前為 2024-05-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         [GC] - Enhanced Relic Log View
// @namespace    https://greasyfork.org/en/users/1225524-kaitlin
// @version      2.0
// @license      MIT
// @description  See additional details related to your relic log, included view filter options.
// @author       Cupkait
// @match        https://www.grundos.cafe/space/warehouse/*
// @match        https://www.grundos.cafe/safetydeposit/*&category=999*
// @grant        none
// @icon        https://i.imgur.com/4Hm2e6z.png
// ==/UserScript==

if (window.location.href.includes('/warehouse/relics/')) {
    var pageContent = document.getElementById('page_content');
    var relicCountElement = document.querySelector("#page_content > main > div.center > p:nth-child(2)");

    var relicCount = relicCountElement.innerText.replace(/[^\d/]/g, '');
    var [countLogged, relicTotal] = relicCount.split('/').map(value => parseInt(value.trim(), 10));

    var countNeeded = relicTotal - countLogged;
    var relicPercent = ((countLogged / relicTotal) * 100).toFixed(1);

    relicCountElement.innerHTML += `<br>Your collection is <strong>${relicPercent}%</strong> complete.<br> You are missing <strong>${countNeeded}</strong> relics.<br> Click <a href="https://www.grundos.cafe/safetydeposit/?query=&category=999&sort=count">here</a> to check for them in your SDB.`;

    var dropdown = document.createElement('select');
    dropdown.id = 'orderDropdown';
    dropdown.style.marginLeft = '10px';
    dropdown.style.marginBottom = '10px';

    var createOption = (value, text, disabled = false, selected = false) => {
        var option = document.createElement('option');
        option.value = value;
        option.text = text;
        option.disabled = disabled;
        option.selected = selected;
        return option;
    };

    dropdown.add(createOption('choose_view', 'Choose View', true, true));

    var options = ['Show Needed', 'Show Logged', 'Show All'];
    options.forEach(optionText => {
        dropdown.add(createOption(optionText.toLowerCase().replace(' ', '_'), optionText));
    });

    var selectedOption = localStorage.getItem('selectedOption');
    if (selectedOption) {
        dropdown.value = selectedOption;
    }

    relicCountElement.parentNode.insertBefore(dropdown, relicCountElement.nextSibling);
    var flexColumns = document.querySelectorAll('.flex-column');
    var notLoggedSet = new Set();

    dropdown.addEventListener('change', function () {
        applySelectedOption();
        localStorage.setItem('selectedOption', dropdown.value);
    });

    flexColumns.forEach(flexColumn => {
        var imagesWithOpacity = flexColumn.querySelectorAll('img[style*="opacity"]');
        var id = imagesWithOpacity.length > 0 ? 'notlogged' : 'reliclogged';
        flexColumn.setAttribute('id', id);

        if (id === 'notlogged') {
            const relicName = flexColumn.querySelector('strong').innerText;
            notLoggedSet.add(relicName);
        }
    });

    var notLoggedArray = Array.from(notLoggedSet);
    var notLoggedJSON = JSON.stringify(notLoggedArray);
    localStorage.setItem('notLoggedRelic', notLoggedJSON);

    function toggleVisibility(elements, displayValue) {
        elements.forEach(element => {
            element.style.display = displayValue;
        });
    }

    function applySelectedOption() {
        var relicLoggedDivs = document.querySelectorAll('#reliclogged');
        var notLoggedDivs = document.querySelectorAll('#notlogged');

        if (dropdown.value === 'show_all') {
            toggleVisibility(relicLoggedDivs, '');
            toggleVisibility(notLoggedDivs, '');
        } else if (dropdown.value === 'show_needed') {
            toggleVisibility(relicLoggedDivs, 'none');
            toggleVisibility(notLoggedDivs, '');
        } else if (dropdown.value === 'show_logged') {
            toggleVisibility(notLoggedDivs, 'none');
            toggleVisibility(relicLoggedDivs, '');
        }
    }

    applySelectedOption();
}

if (window.location.href.includes('/safetydeposit/') && window.location.href.includes('&category=999')) {
    var notLoggedJSON = localStorage.getItem('notLoggedRelic');
    var notLoggedArray = JSON.parse(notLoggedJSON) || [];

    var items = document.querySelectorAll('.flex-column.small-gap.break');

    items.forEach(item => {
        var itemName = item.querySelector('strong').innerText;

        if (notLoggedArray.includes(itemName)) {
            item.style.backgroundColor = 'yellow';
        }
    });
}

if (window.location.href === 'https://www.grundos.cafe/space/warehouse/') {
    var relics = document.querySelectorAll('.relic');

    var notLoggedJSON = localStorage.getItem('notLoggedRelic');
    var notLoggedArray = JSON.parse(notLoggedJSON) || [];

    relics.forEach(relic => {
        var relicName = relic.textContent.trim();

        if (notLoggedArray.includes(relicName)) {
            relic.style.backgroundColor = 'yellow';
        }
    });
}