

{"id":6270,"date":"2024-07-29T18:36:02","date_gmt":"2024-07-29T18:36:02","guid":{"rendered":"https:\/\/aigender.net\/?page_id=6270"},"modified":"2024-07-30T06:04:33","modified_gmt":"2024-07-30T06:04:33","slug":"6270-2","status":"publish","type":"page","link":"https:\/\/aigender.net\/index.php\/6270-2\/","title":{"rendered":"csv"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"mk\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV<\/title>\n    <style>\n        body {\n            font-family: Arial, sans-serif;\n            margin: 20px;\n        }\n        table {\n            width: 100%;\n            border-collapse: collapse;\n            margin-top: 20px;\n        }\n        table, th, td {\n            border: 1px solid black;\n        }\n        th, td {\n            padding: 10px;\n            text-align: left;\n        }\n        th {\n            background-color: #f2f2f2;\n        }\n        button {\n            margin-top: 10px;\n        }\n        textarea {\n            width: 100%;\n            height: 50px;\n            padding: 5px;\n            box-sizing: border-box;\n        }\n    <\/style>\n<\/head>\n<body>\n    <h1>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV<\/h1>\n    <form id=\"column-form\">\n        <input type=\"text\" id=\"column-name\" placeholder=\"\u0418\u043c\u0435 \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u0430\">\n        <button type=\"button\" onclick=\"addColumn()\">\u0414\u043e\u0434\u0430\u0434\u0438 \u043a\u043e\u043b\u043e\u043d\u0430<\/button>\n    <\/form>\n    <form id=\"data-form\">\n        <div id=\"data-inputs\"><\/div>\n        <button type=\"button\" onclick=\"addRow()\">\u0414\u043e\u0434\u0430\u0434\u0438 \u0440\u0435\u0434<\/button>\n    <\/form>\n    <input type=\"file\" id=\"file-input\" accept=\".csv\">\n    <table id=\"data-table\">\n        <thead>\n            <tr id=\"table-header\">\n                <th>\u0414\u0435\u0458\u0441\u0442\u0432\u0430<\/th>\n            <\/tr>\n        <\/thead>\n        <tbody>\n        <\/tbody>\n    <\/table>\n    <button id=\"save-csv\" onclick=\"saveCSV()\">\u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043a\u0430\u043a\u043e CSV<\/button>\n    <button id=\"save-current-csv\" onclick=\"saveCurrentCSV()\">\u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043d\u0430 \u0442\u0435\u043a\u043e\u0432\u043d\u0438\u043e\u0442 \u0444\u0430\u0458\u043b<\/button>\n    <script>\n        let data = [];\n        let columns = [];\n        let currentFileHandle = null;\n\n        document.getElementById('file-input').addEventListener('change', handleFileSelect);\n\n        function addColumn() {\n            const columnName = document.getElementById('column-name').value;\n            if (columnName) {\n                columns.push(columnName);\n                updateInputs();\n                updateTableHeader();\n                document.getElementById('column-form').reset();\n            }\n        }\n\n        function updateInputs() {\n            const dataInputs = document.getElementById('data-inputs');\n            dataInputs.innerHTML = '';\n            columns.forEach(column => {\n                const input = document.createElement('textarea');\n                input.placeholder = column;\n                input.id = column;\n                input.addEventListener('paste', handlePaste);\n                dataInputs.appendChild(input);\n            });\n        }\n\n        function handlePaste(event) {\n            event.preventDefault();\n            const clipboardData = event.clipboardData || window.clipboardData;\n            let pastedData = clipboardData.getData('Text');\n            pastedData = pastedData.replace(\/(\\r\\n|\\n|\\r)\/gm, ' ');\n            document.execCommand('insertText', false, pastedData);\n        }\n\n        function updateTableHeader() {\n            const tableHeader = document.getElementById('table-header');\n            tableHeader.innerHTML = '<th>\u0414\u0435\u0458\u0441\u0442\u0432\u0430<\/th>';\n            columns.forEach((column, index) => {\n                const th = document.createElement('th');\n                th.textContent = column;\n                const deleteBtn = document.createElement('button');\n                deleteBtn.textContent = 'X';\n                deleteBtn.onclick = () => deleteColumn(index);\n                th.appendChild(deleteBtn);\n                tableHeader.appendChild(th);\n            });\n        }\n\n        function addRow() {\n            const rowData = {};\n            let valid = true;\n            columns.forEach(column => {\n                const value = document.getElementById(column).value;\n                if (!value) {\n                    valid = false;\n                }\n                rowData[column] = value;\n            });\n\n            if (valid) {\n                data.push(rowData);\n                updateTable();\n                document.getElementById('data-form').reset();\n            }\n        }\n\n        function updateTable() {\n            const tableBody = document.querySelector('#data-table tbody');\n            tableBody.innerHTML = '';\n            \n            data.forEach((row, rowIndex) => {\n                const tr = document.createElement('tr');\n                const actionsTd = document.createElement('td');\n                actionsTd.innerHTML = `<button onclick=\"deleteRow(${rowIndex})\">\u0418\u0437\u0431\u0440\u0438\u0448\u0438<\/button>`;\n                tr.appendChild(actionsTd);\n                columns.forEach((column, colIndex) => {\n                    const td = document.createElement('td');\n                    const textarea = document.createElement('textarea');\n                    textarea.value = row[column];\n                    textarea.onchange = (e) => updateCell(rowIndex, colIndex, e.target.value);\n                    textarea.addEventListener('paste', handlePaste);\n                    td.appendChild(textarea);\n                    tr.appendChild(td);\n                });\n                tableBody.appendChild(tr);\n            });\n        }\n\n        function deleteRow(index) {\n            data.splice(index, 1);\n            updateTable();\n        }\n\n        function deleteColumn(index) {\n            const column = columns.splice(index, 1)[0];\n            data.forEach(row => {\n                delete row[column];\n            });\n            updateInputs();\n            updateTableHeader();\n            updateTable();\n        }\n\n        function updateCell(rowIndex, colIndex, value) {\n            const column = columns[colIndex];\n            data[rowIndex][column] = value;\n        }\n\n        function saveCSV() {\n            let csvContent = \"\\uFEFF\"; \/\/ UTF-8 BOM\n            csvContent += columns.join(',') + \"\\n\";\n            data.forEach(row => {\n                const rowContent = columns.map(column => `\"${row[column]}\"`).join(',');\n                csvContent += rowContent + \"\\n\";\n            });\n\n            const encodedUri = encodeURI(\"data:text\/csv;charset=utf-8,\" + csvContent);\n            const link = document.createElement(\"a\");\n            link.setAttribute(\"href\", encodedUri);\n            link.setAttribute(\"download\", \"data.csv\");\n            document.body.appendChild(link);\n            link.click();\n            document.body.removeChild(link);\n        }\n\n        async function saveCurrentCSV() {\n            if (!currentFileHandle) {\n                alert('\u041d\u0435\u043c\u0430 \u043e\u0442\u0432\u043e\u0440\u0435\u043d \u0444\u0430\u0458\u043b \u0437\u0430 \u0437\u0430\u0447\u0443\u0432\u0443\u0432\u0430\u045a\u0435.');\n                return;\n            }\n\n            let csvContent = \"\\uFEFF\"; \/\/ UTF-8 BOM\n            csvContent += columns.join(',') + \"\\n\";\n            data.forEach(row => {\n                const rowContent = columns.map(column => `\"${row[column]}\"`).join(',');\n                csvContent += rowContent + \"\\n\";\n            });\n\n            const writable = await currentFileHandle.createWritable();\n            await writable.write(csvContent);\n            await writable.close();\n            alert('\u041f\u0440\u043e\u043c\u0435\u043d\u0438\u0442\u0435 \u0441\u0435 \u0437\u0430\u0447\u0443\u0432\u0430\u043d\u0438.');\n        }\n\n        async function handleFileSelect(event) {\n            const file = event.target.files[0];\n            if (file) {\n                [currentFileHandle] = await window.showOpenFilePicker({\n                    types: [{\n                        description: 'CSV files',\n                        accept: {'text\/csv': ['.csv']}\n                    }],\n                    multiple: false\n                });\n\n                const fileData = await currentFileHandle.getFile();\n                const text = await fileData.text();\n                loadCSV(text);\n            }\n        }\n\n        function loadCSV(text) {\n            const lines = text.split('\\n').filter(line => line.trim() !== '');\n            columns = lines[0].trim().split(',').map(col => col.replace(\/(^\"|\"$)\/g, ''));\n            updateInputs();\n            updateTableHeader();\n            data = lines.slice(1).map(line => {\n                const values = line.trim().split(',').map(val => val.replace(\/(^\"|\"$)\/g, ''));\n                const row = {};\n                columns.forEach((col, index) => {\n                    row[col] = values[index] || '';\n                });\n                return row;\n            });\n            updateTable();\n        }\n    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV \u0414\u043e\u0434\u0430\u0434\u0438 \u043a\u043e\u043b\u043e\u043d\u0430 \u0414\u043e\u0434\u0430\u0434\u0438 \u0440\u0435\u0434 \u0414\u0435\u0458\u0441\u0442\u0432\u0430 \u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043a\u0430\u043a\u043e CSV \u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043d\u0430 \u0442\u0435\u043a\u043e\u0432\u043d\u0438\u043e\u0442 \u0444\u0430\u0458\u043b<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"slim_seo":{"title":"csv - \u041a\u043e\u0440\u0438\u0441\u0442\u0435\u045a\u0435 \u043d\u0430 \u0432\u0435\u0448\u0442\u0430\u0447\u043a\u0430\u0442\u0430 \u0438\u043d\u0442\u0435\u043b\u0438\u0433\u0435\u043d\u0446\u0438\u0458\u0430 (AI) \u0437\u0430 \u0443\u043d\u0430\u043f\u0440\u0435\u0434\u0443\u0432\u0430\u045a\u0435 \u043d\u0430 \u0440\u043e\u0434\u043e\u0432\u0430\u0442\u0430 \u0435\u0434\u043d\u0430\u043a\u0432\u043e\u0441\u0442","description":"\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 CSV \u0414\u043e\u0434\u0430\u0434\u0438 \u043a\u043e\u043b\u043e\u043d\u0430 \u0414\u043e\u0434\u0430\u0434\u0438 \u0440\u0435\u0434 \u0414\u0435\u0458\u0441\u0442\u0432\u0430 \u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043a\u0430\u043a\u043e CSV \u0417\u0430\u0447\u0443\u0432\u0430\u0458 \u043d\u0430 \u0442\u0435\u043a\u043e\u0432\u043d\u0438\u043e\u0442 \u0444\u0430\u0458\u043b"},"footnotes":""},"class_list":["post-6270","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/pages\/6270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/comments?post=6270"}],"version-history":[{"count":10,"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/pages\/6270\/revisions"}],"predecessor-version":[{"id":6294,"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/pages\/6270\/revisions\/6294"}],"wp:attachment":[{"href":"https:\/\/aigender.net\/index.php\/wp-json\/wp\/v2\/media?parent=6270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}