From 7285c8d47d9bfd22fd4c828209421296b6d5cc80 Mon Sep 17 00:00:00 2001 From: "DESKTOP-57U3QJV\\user01" Date: Tue, 26 Dec 2023 17:01:15 +0800 Subject: [PATCH 1/2] Performance optimization: CSV data preprocessing --- index.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 51eaf38..573b3bd 100644 --- a/index.html +++ b/index.html @@ -73,8 +73,12 @@ // 用 pako 解壓縮 var csvData = pako.inflate(uintArray, { to: 'string' }); - // 文字框改變時 call searchCSV() + // CSV 資料預處理 + var lines = csvData.split('\n').map(function(line) { + return removeAccents(line.toLowerCase()); + }); + // 文字框改變時 call searchCSV() function searchCSV() { var input = removeAccents(document.getElementById('searchInput').value.toLowerCase()); @@ -84,13 +88,11 @@ return; } - var lines = csvData.split('\n'); var matchingLines = ''; // 搜尋每一行 for (var i = 0; i < lines.length; i++) { - var line = removeAccents(lines[i].toLowerCase()); - if (line.includes(input)) { + if (lines[i].includes(input)) { matchingLines += lines[i] + '
'; } } From 76333fbdef295d1e4b510b39316f5e9283b47003 Mon Sep 17 00:00:00 2001 From: "DESKTOP-57U3QJV\\user01" Date: Wed, 27 Dec 2023 10:12:19 +0800 Subject: [PATCH 2/2] Fix bug: Corrected output information --- index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 573b3bd..b01d5d3 100644 --- a/index.html +++ b/index.html @@ -74,8 +74,8 @@ var csvData = pako.inflate(uintArray, { to: 'string' }); // CSV 資料預處理 - var lines = csvData.split('\n').map(function(line) { - return removeAccents(line.toLowerCase()); + var lines = csvData.split('\n').map(line => { + return [removeAccents(line.toLowerCase()), line]; }); // 文字框改變時 call searchCSV() @@ -92,8 +92,8 @@ // 搜尋每一行 for (var i = 0; i < lines.length; i++) { - if (lines[i].includes(input)) { - matchingLines += lines[i] + '
'; + if (lines[i][0].includes(input)) { + matchingLines += lines[i][1] + '
'; } }