Infinite Craft Rarity Highlighter

Highlight words with rarity based on difficulty when dragged out of the panel

目前为 2024-11-26 提交的版本。查看 最新版本

// ==UserScript==
// @name         Infinite Craft Rarity Highlighter
// @namespace    http://tampermonkey.net/
// @version      beta 4.6
// @description  Highlight words with rarity based on difficulty when dragged out of the panel
// @author       carbonara crab
// @match        https://neal.fun/infinite-craft/
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    console.log('Script activated for Infinite Craft'); // Log to indicate the script has started

    // Function to determine rarity based on text length
    function getRarity(textLength) {
        if (textLength <= 29) return 'common';
        if (textLength <= 35) return 'uncommon';
        if (textLength <= 45) return 'rare';
        if (textLength <= 68) return 'epic';
        if (textLength <= 107) return 'legendary';
        return 'exotic';
    }

    // Function to get color based on rarity
    function getColor(rarity) {
        switch (rarity) {
            case 'common': return 'white';
            case 'uncommon': return 'lightgreen';
            case 'rare': return 'cornflowerblue';
            case 'epic': return 'plum';
            case 'legendary': return 'gold';
            case 'exotic': return 'cyan';
            default: return 'black';
        }
    }

    // Function to highlight the element based on text length
    function highlightElement(element) {
        if (!element || !element.textContent) {
            console.log('No valid element or text content found.');
            return;
        }
        const textLength = element.textContent.length;
        const rarity = getRarity(textLength);
        const color = getColor(rarity);
        console.log(`Element: ${element}, Text Length: ${textLength}, Rarity: ${rarity}, Color: ${color}`); // Debugging line
        element.style.color = color;
    }

    // Function to handle the drag and drop events
    function handleDragAndDrop(event) {
        const element = event.target.closest('.item'); // General selector for Infinite Craft items
        if (element) {
            console.log('Element dragged:', element); // Log the element being dragged
            document.addEventListener('mouseup', function mouseUpHandler(e) {
                document.removeEventListener('mouseup', mouseUpHandler);
                // Check if the element is outside the panel and is the newly created element
                if (!element.closest('.side-panel') && e.target !== element) {
                    highlightElement(e.target);
                }
            });
        } else {
            console.log('No valid Infinite Craft item detected.');
        }
    }

    // Function to check if the mouse is over an Infinite Craft element
    function isHoveringOverElement(event) {
        const element = document.elementFromPoint(event.clientX, event.clientY);
        console.log('Hovering over element:', element); // Log the element being hovered over
        return element && element.closest('.side-panel');
    }

    // Function to dynamically find the side panel
    function findSidePanel() {
        const panels = document.querySelectorAll('*');
        for (const panel of panels) {
            if (panel.textContent.includes('Infinite Craft')) {
                return panel;
            }
        }
        return null;
    }

    // Add event listener for mousedown event
    document.addEventListener('mousedown', function(event) {
        console.log('Mouse down event detected'); // Log the mousedown event
        const sidePanel = findSidePanel();
        if (sidePanel && sidePanel.contains(event.target)) {
            console.log('Hovering over a valid element'); // Log if hovering over a valid element
            handleDragAndDrop(event);
        }
    });

    console.log('Event listener added'); // Log to indicate the event listener has been added

})();

QingJ © 2025

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