文件編輯html

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>文件行內容編輯器</title><script src="https://cdn.tailwindcss.com"></script><link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet"><!-- Tailwind 配置 --><script>tailwind.config = {theme: {extend: {colors: {primary: '#3B82F6',secondary: '#10B981',accent: '#6366F1',neutral: '#1F2937',danger: '#EF4444',},fontFamily: {sans: ['Inter', 'system-ui', 'sans-serif'],mono: ['Fira Code', 'monospace'],},}}}</script><style type="text/tailwindcss">@layer utilities {.content-auto {content-visibility: auto;}.text-shadow {text-shadow: 0 2px 4px rgba(0,0,0,0.1);}.transition-height {transition: max-height 0.3s ease-in-out;}.line-number {user-select: none;}}</style>
</head>
<body class="bg-gray-50 min-h-screen font-sans text-gray-800"><!-- 頂部導航 --><header class="bg-white shadow-md fixed w-full top-0 z-50 transition-all duration-300" id="header"><div class="container mx-auto px-4 py-3 flex justify-between items-center"><div class="flex items-center space-x-2"><i class="fa fa-file-text-o text-primary text-2xl"></i><h1 class="text-xl font-bold text-neutral">文件行內容編輯器</h1></div><div class="hidden md:flex items-center space-x-6"><a href="#" class="text-gray-600 hover:text-primary transition-colors duration-200 flex items-center"><i class="fa fa-question-circle mr-1"></i> 幫助</a><a href="#" class="text-gray-600 hover:text-primary transition-colors duration-200 flex items-center"><i class="fa fa-info-circle mr-1"></i> 關于</a></div></div></header><!-- 主內容區 --><main class="container mx-auto px-4 pt-24 pb-16"><!-- 上傳區域 --><section class="mb-10 bg-white rounded-xl shadow-lg p-6 transform transition-all duration-300 hover:shadow-xl"><h2 class="text-xl font-semibold mb-4 text-neutral flex items-center"><i class="fa fa-upload text-primary mr-2"></i> 上傳文件</h2><div class="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-primary transition-colors duration-300" id="drop-area"><i class="fa fa-file-text-o text-5xl text-gray-400 mb-4"></i><p class="mb-4 text-gray-600">拖放文件到此處,或點擊選擇文件</p><label class="inline-block bg-primary hover:bg-primary/90 text-white font-medium py-2 px-6 rounded-lg cursor-pointer transition-all duration-200 transform hover:scale-105"><i class="fa fa-folder-open mr-1"></i> 選擇文件<input type="file" id="file-input" class="hidden" accept=".txt,.c,.cpp,.h,.py,.java,.js,.html,.css,.php"></label><p class="mt-4 text-sm text-gray-500">支持的格式: .txt, .c, .cpp, .h, .py, .java, .js, .html, .css, .php</p></div><div id="file-info" class="mt-4 hidden"><div class="flex items-center p-3 bg-gray-50 rounded-lg border border-gray-200"><i class="fa fa-file text-primary mr-3"></i><div class="flex-grow"><p id="file-name" class="font-medium"></p><p id="file-size" class="text-sm text-gray-500"></p></div><button id="remove-file" class="text-gray-400 hover:text-danger transition-colors"><i class="fa fa-times"></i></button></div></div></section><!-- 文件內容和編輯區域 --><section class="grid grid-cols-1 lg:grid-cols-3 gap-6" id="editor-section"><!-- 左側:文件內容顯示 --><div class="lg:col-span-2"><div class="bg-white rounded-xl shadow-lg p-6 h-full"><h2 class="text-xl font-semibold mb-4 text-neutral flex items-center"><i class="fa fa-file-code-o text-primary mr-2"></i> 文件內容</h2><div class="relative"><div class="absolute left-0 top-0 bottom-0 bg-gray-50 border-r border-gray-200 px-3 py-2 overflow-hidden"><pre id="line-numbers" class="text-right text-gray-500 font-mono text-sm line-number"></pre></div><div class="ml-10 pl-4 border-l border-gray-100"><pre id="file-content" class="font-mono text-sm whitespace-pre-wrap break-all max-h-[500px] overflow-auto"></pre></div></div><div class="mt-4 flex justify-between items-center"><div class="text-sm text-gray-500"><span id="total-lines">0 行</span></div><button id="download-file" class="hidden bg-secondary hover:bg-secondary/90 text-white font-medium py-2 px-4 rounded-lg transition-all duration-200 flex items-center"><i class="fa fa-download mr-1"></i> 下載修改后的文件</button></div></div></div><!-- 右側:編輯控制區 --><div><div class="bg-white rounded-xl shadow-lg p-6 h-full"><h2 class="text-xl font-semibold mb-4 text-neutral flex items-center"><i class="fa fa-pencil text-primary mr-2"></i> 行編輯</h2><div id="edit-controls" class="space-y-4 opacity-50 pointer-events-none"><!-- 行號輸入 --><div><label for="line-number" class="block text-sm font-medium text-gray-700 mb-1">行號</label><div class="flex"><input type="number" id="line-number" min="1" class="flex-grow px-3 py-2 border border-gray-300 rounded-l-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary" placeholder="輸入行號"><button id="goto-line" class="bg-primary hover:bg-primary/90 text-white px-4 rounded-r-lg transition-colors"><i class="fa fa-search"></i></button></div></div><!-- 當前行內容 --><div><label class="block text-sm font-medium text-gray-700 mb-1">當前行內容</label><div class="relative"><textarea id="current-line-content" class="w-full px-3 py-2 border border-gray-300 rounded-lg bg-gray-50 focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary h-24 resize-none" readonly placeholder="選中行后顯示內容"></textarea></div></div><!-- 替換內容 --><div><label for="replace-content" class="block text-sm font-medium text-gray-700 mb-1">替換為</label><textarea id="replace-content" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary h-24 resize-none" placeholder="輸入替換內容"></textarea></div><!-- 操作按鈕 --><div class="flex space-x-3 pt-2"><button id="replace-line" class="flex-grow bg-accent hover:bg-accent/90 text-white font-medium py-2 px-4 rounded-lg transition-all duration-200 transform hover:scale-[1.02]"><i class="fa fa-exchange mr-1"></i> 替換</button><button id="reset-edits" class="bg-gray-200 hover:bg-gray-300 text-gray-700 font-medium py-2 px-4 rounded-lg transition-colors"><i class="fa fa-refresh"></i></button></div></div><!-- 狀態消息 --><div id="status-message" class="mt-6 p-3 rounded-lg hidden"></div></div></div></section></main><!-- 頁腳 --><footer class="bg-neutral text-white py-6"><div class="container mx-auto px-4 text-center"><p>文件行內容編輯器 &copy; 2023</p><p class="text-gray-400 text-sm mt-1">安全提示:所有文件操作均在本地進行,不會上傳到服務器</p></div></footer><!-- JavaScript --><script>// 全局變量let fileContent = [];let originalFileContent = [];let currentFile = null;let highlightedLine = null;// DOM 元素const dropArea = document.getElementById('drop-area');const fileInput = document.getElementById('file-input');const fileInfo = document.getElementById('file-info');const fileName = document.getElementById('file-name');const fileSize = document.getElementById('file-size');const removeFile = document.getElementById('remove-file');const fileContentEl = document.getElementById('file-content');const lineNumbersEl = document.getElementById('line-numbers');const totalLinesEl = document.getElementById('total-lines');const lineNumberInput = document.getElementById('line-number');const gotoLineBtn = document.getElementById('goto-line');const currentLineContent = document.getElementById('current-line-content');const replaceContent = document.getElementById('replace-content');const replaceLineBtn = document.getElementById('replace-line');const resetEditsBtn = document.getElementById('reset-edits');const statusMessage = document.getElementById('status-message');const downloadFileBtn = document.getElementById('download-file');const editControls = document.getElementById('edit-controls');const header = document.getElementById('header');// 頁面滾動事件 - 改變導航欄樣式window.addEventListener('scroll', () => {if (window.scrollY > 10) {header.classList.add('py-2', 'shadow-lg');header.classList.remove('py-3', 'shadow-md');} else {header.classList.add('py-3', 'shadow-md');header.classList.remove('py-2', 'shadow-lg');}});// 顯示狀態消息function showStatus(message, isError = false) {statusMessage.textContent = message;statusMessage.classList.remove('hidden', 'bg-green-100', 'text-green-800', 'bg-red-100', 'text-red-800');if (isError) {statusMessage.classList.add('bg-red-100', 'text-red-800');} else {statusMessage.classList.add('bg-green-100', 'text-green-800');}// 3秒后自動隱藏setTimeout(() => {statusMessage.classList.add('hidden');}, 3000);}// 渲染文件內容function renderFileContent() {// 清空內容fileContentEl.innerHTML = '';lineNumbersEl.innerHTML = '';// 渲染每一行fileContent.forEach((line, index) => {// 創建行號const lineNumber = document.createElement('span');lineNumber.textContent = `${index + 1}\n`;lineNumber.classList.add('block', 'py-0.5');if (highlightedLine === index + 1) {lineNumber.classList.add('text-primary', 'font-bold');}lineNumbersEl.appendChild(lineNumber);// 創建內容行const contentLine = document.createElement('span');contentLine.textContent = line;contentLine.classList.add('block', 'py-0.5', 'whitespace-pre-wrap');if (highlightedLine === index + 1) {contentLine.classList.add('bg-primary/10', 'font-medium');}// 點擊行號選擇行contentLine.addEventListener('click', () => {selectLine(index + 1);});fileContentEl.appendChild(contentLine);});// 更新總行數totalLinesEl.textContent = `${fileContent.length}`;}// 選擇行function selectLine(lineNumber) {if (lineNumber < 1 || lineNumber > fileContent.length) {showStatus('無效的行號', true);return;}// 更新高亮行highlightedLine = lineNumber;// 更新輸入框lineNumberInput.value = lineNumber;// 顯示當前行內容currentLineContent.value = fileContent[lineNumber - 1];// 滾動到選中的行const lineElements = fileContentEl.querySelectorAll('span');if (lineElements[lineNumber - 1]) {lineElements[lineNumber - 1].scrollIntoView({ behavior: 'smooth', block: 'center' });}// 重新渲染renderFileContent();}// 處理文件function handleFile(file) {currentFile = file;// 顯示文件信息fileName.textContent = file.name;fileSize.textContent = `${(file.size / 1024).toFixed(2)} KB`;fileInfo.classList.remove('hidden');// 讀取文件內容const reader = new FileReader();reader.onload = (e) => {// 按行分割內容fileContent = e.target.result.split('\n');originalFileContent = [...fileContent]; // 保存原始內容用于重置// 啟用編輯控件editControls.classList.remove('opacity-50', 'pointer-events-none');// 顯示下載按鈕downloadFileBtn.classList.remove('hidden');// 渲染內容renderFileContent();showStatus(`成功加載文件: ${file.name}`);};reader.onerror = () => {showStatus('讀取文件時出錯', true);};reader.readAsText(file);}// 拖放事件['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {dropArea.addEventListener(eventName, preventDefaults, false);});function preventDefaults(e) {e.preventDefault();e.stopPropagation();}['dragenter', 'dragover'].forEach(eventName => {dropArea.addEventListener(eventName, highlight, false);});['dragleave', 'drop'].forEach(eventName => {dropArea.addEventListener(eventName, unhighlight, false);});function highlight() {dropArea.classList.add('border-primary', 'bg-primary/5');}function unhighlight() {dropArea.classList.remove('border-primary', 'bg-primary/5');}dropArea.addEventListener('drop', handleDrop, false);function handleDrop(e) {const dt = e.dataTransfer;const file = dt.files[0];if (file) {handleFile(file);}}// 文件選擇事件fileInput.addEventListener('change', (e) => {const file = e.target.files[0];if (file) {handleFile(file);}});// 移除文件removeFile.addEventListener('click', () => {fileInput.value = '';fileInfo.classList.add('hidden');fileContent = [];originalFileContent = [];currentFile = null;highlightedLine = null;currentLineContent.value = '';replaceContent.value = '';lineNumberInput.value = '';editControls.classList.add('opacity-50', 'pointer-events-none');downloadFileBtn.classList.add('hidden');renderFileContent();showStatus('文件已移除');});// 跳轉到指定行gotoLineBtn.addEventListener('click', () => {const lineNumber = parseInt(lineNumberInput.value);if (!isNaN(lineNumber)) {selectLine(lineNumber);} else {showStatus('請輸入有效的行號', true);}});// 按Enter鍵跳轉到指定行lineNumberInput.addEventListener('keypress', (e) => {if (e.key === 'Enter') {gotoLineBtn.click();}});// 替換行內容replaceLineBtn.addEventListener('click', () => {const lineNumber = parseInt(lineNumberInput.value);if (isNaN(lineNumber) || lineNumber < 1 || lineNumber > fileContent.length) {showStatus('請選擇有效的行號', true);return;}const newContent = replaceContent.value;// 替換內容fileContent[lineNumber - 1] = newContent;// 更新當前行內容顯示currentLineContent.value = newContent;// 重新渲染renderFileContent();showStatus(`${lineNumber} 行已更新`);});// 重置編輯resetEditsBtn.addEventListener('click', () => {if (originalFileContent.length > 0) {fileContent = [...originalFileContent];currentLineContent.value = '';replaceContent.value = '';lineNumberInput.value = '';highlightedLine = null;renderFileContent();showStatus('已重置為原始文件內容');}});// 下載文件downloadFileBtn.addEventListener('click', () => {if (!currentFile || fileContent.length === 0) return;// 合并行內容const content = fileContent.join('\n');// 創建Blobconst blob = new Blob([content], { type: 'text/plain' });// 創建下載鏈接const url = URL.createObjectURL(blob);const a = document.createElement('a');a.href = url;// 生成新文件名const originalName = currentFile.name;const extensionIndex = originalName.lastIndexOf('.');let newName;if (extensionIndex > 0) {newName = `${originalName.substring(0, extensionIndex)}-modified${originalName.substring(extensionIndex)}`;} else {newName = `${originalName}-modified`;}a.download = newName;document.body.appendChild(a);a.click();// 清理setTimeout(() => {document.body.removeChild(a);URL.revokeObjectURL(url);}, 0);showStatus(`文件已下載: ${newName}`);});// 點擊上傳區域打開文件選擇dropArea.addEventListener('click', () => {fileInput.click();});</script>
</body>
</html>

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/92958.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/92958.shtml
英文地址,請注明出處:http://en.pswp.cn/web/92958.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

具有熔斷能力和活性探測的服務負載均衡解決方案

一、整體架構設計 1.核心組件 負載均衡器&#xff1a;負責選擇可用的服務節點健康檢查器&#xff1a;定期檢測服務節點的可用性服務節點管理&#xff1a;維護所有可用節點的狀態信息 2.負載均衡策略 輪詢(Round Robin)隨機(Random)加權輪詢(Weighted Round Robin)最少連接(Leas…

技術演進中的開發沉思-62 DELPHI VCL系列:VCL下的設計模式

今天聊聊設計模式&#xff0c;當然這個章節目前僅限于DELPHI VCL,因為接下來梳理的Factory/Factory Method、Bootstrap 和 ForEach 這三種設計樣例&#xff0c;看似獨立&#xff0c;卻在實際開發中相互配合&#xff0c;共同構建起高效、靈活的程序架構。在 DELPHI VCL 開發的技…

Docker 101:面向初學者的綜合教程

掌握 Docker 已成為軟件開發中的一項關鍵技能。本教程探討了容器化的世界&#xff0c;包括其核心概念、優缺點&#xff0c;以及開始使用容器化的分步指南。 無論是 Docker 的新手&#xff0c;還是希望復習基礎知識的更有經驗的開發人員&#xff0c;本指南都能滿足需求。 什么…

RTOS YAFFS

在 YAFFS (Yet Another Flash File System) 的語境中&#xff0c;“Check Point” 并不是一個標準的、核心的官方術語。它更可能是對 YAFFS 關鍵機制 Summary 或 Checkpointing 功能的非正式表述或理解偏差。其核心含義是指 YAFFS 在特定時刻保存文件系統關鍵元數據的狀態&…

【SpringBoot系列-02】自動配置機制源碼剖析

【SpringBoot系列-02】自動配置機制源碼剖析 咱們天天用Spring Boot&#xff0c;一個SpringBootApplication注解扔進去&#xff0c;啥配置都不用寫&#xff0c;項目就跑起來了。你有沒有過這種疑惑&#xff1a;那些DispatcherServlet、DataSource是從哪冒出來的&#xff1f;今天…

51單片機-51單片機最小系統

本章概述思維導圖&#xff1a;51單片機最小系統51單片機最小系統是51系列單片機&#xff08;如AT89C51、STC89C52等&#xff09;能夠獨立工作的最簡電路配置&#xff0c;它為單片機提供了運行所需的基本條件。51單片機最小系統板是嵌入式系統開發的基礎平臺&#xff0c;集成了單…

git學習1

目錄引入版本控制集中式和分布式版本控制git工作機制代碼托管中心Git常用命令設置用戶簽名初始化本地庫查看庫狀態add和提交版本穿梭git分支操作分支定義分支好處分支操作查看分支創建分支切換分支分支合并&#x1f495;?&#x1fa77;合并沖突git團隊協作團隊內協作跨團隊協作…

redis原理篇--Dict

Dict數據結構一、Redis字典的核心組件Redis字典由三部分構成&#xff1a;dictht&#xff08;哈希表&#xff09;&#xff1a;存儲桶數組與元數據dictEntry&#xff08;哈希節點&#xff09;&#xff1a;存儲鍵值對dict&#xff08;字典主體&#xff09;&#xff1a;包含雙哈希表…

靜態路由主備切換

在網絡中&#xff0c;靜態路由的主備切換是實現網絡冗余的基礎方案之一&#xff0c;通過配置不同優先級的靜態路由&#xff0c;確保主用路徑故障時&#xff0c;流量能自動切換到備用路徑&#xff0c;提升網絡可靠性。以下從知識講解和實驗配置兩部分詳細說明。一、靜態路由主備…

PDF處理控件Aspose.PDF教程:在C#、Java、Python中快速縮小PDF

如果您的PDF太大&#xff0c;無法通過電子郵件發送&#xff0c;或者在線加載時間過長&#xff0c;您可以在幾秒鐘內縮小 PDF 大小。本教程介紹了借助Aspose.PDF使用 C#、Java 和 Python 編程快速縮小PDF的方法。 Aspose.PDF官方試用版下載 通過編程縮小 PDF 尺寸 如果您需要…

AWS EKS 常用命令大全:從基礎管理到高級運維

前言 Amazon Elastic Kubernetes Service (EKS) 是 AWS 提供的托管 Kubernetes 服務,大大簡化了 K8s 集群的部署和管理工作。作為 EKS 管理員或開發者,熟練掌握 kubectl 命令是日常工作的基礎。本文將詳細介紹 EKS 環境中常用的 kubectl 命令,涵蓋集群管理、工作負載操作、…

GitHub Browser-Use 的部署失敗記錄:失敗了,失敗了。。。。

一、項目背景與核心作用 browser-use 是一個開源的瀏覽器自動化工具&#xff0c;通過集成 AI 智能體&#xff08;如 GPT、Claude、DeepSeek 等大型語言模型&#xff09;&#xff0c;實現用自然語言控制瀏覽器操作。其核心目標是 簡化網頁交互自動化&#xff0c;尤其適合復雜、…

調用springboot接口返回403,問題定位及總結

背景在一次與前端聯調后端接口時前端返回接口返回狀態碼是403&#xff0c;前端返回說已經帶了請求token。排查 查看后端控制臺沒有出現任何錯誤信息。自己postman手動調用接口&#xff0c;發現接口正常。仔細核對前端調用接口與postman請求的區別&#xff0c;沒有發現任何問題。…

布隆過濾器原理分析、應用場景、與redis使用案例

一、核心結構與工作原理1.1 數據結構布隆過濾器由以下兩部分組成&#xff1a;位數組&#xff08;Bit Array&#xff09;&#xff1a;一個長度為 m 的二進制數組&#xff0c;初始所有位為0。哈希函數組&#xff1a;k 個獨立的哈希函數&#xff0c;每個函數將輸入元素映射到位數組…

異步并發×編譯性能:Dart爬蟲的實戰突圍

Dart憑借其高效的異步并發模型、AOT編譯性能和現代化的語法&#xff0c;正成為爬蟲開發中值得關注的新選擇。特別是對于Flutter應用開發者而言&#xff0c;Dart提供了一種"全棧同語言"的獨特優勢。 本文我將通過實戰代碼展示如何利用Dart的核心優勢——包括基于Futur…

Day 8: 深度學習綜合實戰與進階技術 - 從優化到部署的完整流程

Day 8: 深度學習綜合實戰與進階技術 - 從優化到部署的完整流程 ?? 學習目標: 掌握深度學習模型優化、調試、遷移學習等工業級技能,能夠構建高性能的深度學習應用 ?? 核心概念概覽 核心概念解釋: 模型優化: 通過正則化、學習率調度等技術提升模型性能和泛化能力 為什么需…

特征工程--機器學習

1、特征工程1.1 概念特征工程&#xff08;Feature Engineering&#xff09;是機器學習項目中非常關鍵的一步&#xff0c;它是指通過領域知識來選擇、創建或修改能夠使機器學習模型更好地工作的特征&#xff08;即輸入變量&#xff09;。特征工程的目標是提高模型的性能&#xf…

支持任意 MCP 協議的客戶端

支持任意 MCP 協議的客戶端&#xff08;如&#xff1a;Cursor、Claude、Cline&#xff09;可方便使用高德地圖 MCP server。目前支持Streamable HTTP, SSE 和 Node.js I/O 三種接入方式(推薦用戶使用Streamable HTTP)。 快速接入-MCP Server|高德地圖API

【線性代數】目錄

【線性代數】線性方程組與矩陣——&#xff08;1&#xff09;線性方程組與矩陣初步【線性代數】線性方程組與矩陣——行列式【線性代數】線性方程組與矩陣——&#xff08;2&#xff09;矩陣與線性方程組的解【線性代數】線性方程組與矩陣——&#xff08;3&#xff09;線性方程…

豆包新模型+PromptPilot:AI應用開發全流程實戰指南

> 當深度推理的豆包大模型遇上智能提示詞引擎,傳統AI開發中**70%的調試時間被壓縮至幾分鐘**,一場從“手工調參”到“智能優化”的開發范式革命正在發生。 ## 一、技術架構解析:雙引擎驅動智能進化 ### 1.1 豆包新模型的技術突破 2025年火山引擎推出的**豆包1.6系列模型…