NBT File Loader for CraftNite

Parse NBT files (like .schematic files) in the browser

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NBT File Loader for CraftNite
// @namespace    cheatnite69
// @version      1.1
// @description  Parse NBT files (like .schematic files) in the browser
// @author       unknown
// @match        https://craftnite.io/*
// @run-at       document-start
// @license      MIT
// @grant        GM_addStyle
// ==/UserScript==


function handleNBTFileUpload(file) {
    const reader = new FileReader();

    reader.onload = function(event) {
        const data = event.target.result;

        try {
            const parsed = NBT.parse(data); 
            console.log(parsed);

            const entities = parsed.Entities || [];
            const blocks = parsed.Blocks || [];
            console.log('Entities:', entities);
            console.log('Blocks:', blocks);
        } catch (error) {
            console.error('Error parsing NBT file:', error);
        }
    };

    reader.onerror = function(error) {
        console.error('Error reading the file:', error);
    };

    reader.readAsArrayBuffer(file);  
}


function createFileUpload() {
    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.schematic';  
    fileInput.style.display = 'none';  

    fileInput.addEventListener('change', function(event) {
        const file = event.target.files[0];
        if (file) {
            handleNBTFileUpload(file);  
        }
    });

    
    const uploadButton = document.createElement('button');
    uploadButton.innerText = 'Upload .schematic File';
    uploadButton.style.fontSize = '20px';        
    uploadButton.style.padding = '10px 20px';    
    uploadButton.style.margin = '10px';          
    uploadButton.style.cursor = 'pointer';         
    uploadButton.style.position = 'fixed';  
    uploadButton.style.top = '10px';  
    uploadButton.style.right = '10px';   Seite
    uploadButton.style.backgroundColor = '#4CAF50'; 
    uploadButton.style.color = 'white';           
    uploadButton.style.border = 'none';         
    uploadButton.style.borderRadius = '5px';     

    uploadButton.addEventListener('click', function() {
        fileInput.click(); 
    });

    document.body.appendChild(uploadButton);  
    document.body.appendChild(fileInput);     
}

const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/nbt-js/dist/nbt.min.js';
script.onload = function() {
    createFileUpload(); 
};
document.head.appendChild(script);