diff options
Diffstat (limited to 'irclog')
| -rw-r--r-- | irclog/deploy.sh | 2 | ||||
| -rw-r--r-- | irclog/search/index.html | 62 | ||||
| -rw-r--r-- | irclog/search/search.js | 112 | ||||
| -rw-r--r-- | irclog/view/index.html | 11 | ||||
| -rw-r--r-- | irclog/view/view1.js (renamed from irclog/view/view.js) | 8 |
5 files changed, 191 insertions, 4 deletions
diff --git a/irclog/deploy.sh b/irclog/deploy.sh new file mode 100644 index 0000000..d758f08 --- /dev/null +++ b/irclog/deploy.sh @@ -0,0 +1,2 @@ +rsync -avz ./view/ root@raye:/volume/webroot/irclog/view/ +rsync -avz ./search/ root@raye:/volume/webroot/irclog/search/ diff --git a/irclog/search/index.html b/irclog/search/index.html new file mode 100644 index 0000000..066b30d --- /dev/null +++ b/irclog/search/index.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html lang="zh"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"> + <title>IRC Log Viewer</title> + <style> + body { + font-family: Arial, sans-serif; + max-width: 1200px; + margin: 20px; + background-color: #f4f4f4; + } + #log-container { + border: 1px solid #ccc; + padding: 15px; + background-color: #fff; + white-space: pre-wrap; + } + pre { + font-family: Consolas, monospace; + margin: 0; + padding: 0; + overflow-wrap: anywhere; + white-space: pre-wrap; + } + .error { + color: red; + font-weight: bold; + } + .loading { + color: blue; + } + + @media (max-width: 600px) { + pre { + font-size: 0.7em; + } + } + #searchlink { + visibility: hidden; + } + a:link, + a:visited { + color: blue; + text-decoration: underline; + } + </style> +</head> +<body> + + <h1>IRC日志检索</h1> + <div id="controls"> + <input type="text" id="query" value=""> + <button onclick="search()">搜索</button> + <br> + <br> + </div> + <div id="log-container"></div> + <script src="./search.js"></script> +</body> +</html> diff --git a/irclog/search/search.js b/irclog/search/search.js new file mode 100644 index 0000000..9a574d6 --- /dev/null +++ b/irclog/search/search.js @@ -0,0 +1,112 @@ +const logContainer = document.getElementById('log-container'); +const queryInput = document.getElementById('query'); + +const queryString = window.location.search; +const urlParams = new URLSearchParams(queryString); +let query = urlParams.get('q'); +if (query === null) { + query = ''; +} else { + queryInput.value = query.trim(); +} + +logContainer.innerHTML = ''; + +function escapeHtml(unsafe) { + if (!unsafe) return ''; + return unsafe + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + +function ircAction(text) { + const regex = + /^(\[[^\]]+\])(\s*<)([^>]+)(>:\s*)(\u0001ACTION\s+)([^\u0001]+)(\u0001)(.*)$/gm; + const replacement = '$1 * $3 $6$8'; + return text.replace(regex, replacement); +} + +function linkify(text) { + const urlRegex = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + return text.replace(urlRegex, function(url) { + return `<a href="${url}" target="_blank">${url}</a>`; + }); +} + +function aggrLog(data) { + const logsByDate = {}; + const lines = data.trim().split('\n'); + + lines.forEach(line => { + const match = line.match(/^\.\/(\d{4}\/\d{2}-\d{2})\.txt:(.*)/); + if (match) { + const fullDate = match[1].replace('/', '-'); + const logContent = match[2].trim(); + if (!logsByDate[fullDate]) { + logsByDate[fullDate] = []; + } + logsByDate[fullDate].push(logContent); + } + }); + const dates = Object.keys(logsByDate); + const sortedDates = dates.sort().reverse(); + let ret = ''; + sortedDates.forEach(date => { + year = date.substring(0, 4); + month = date.substring(5, 7); + day = date.substring(8, 10); + url = '../view/?chan=main&y=' + year + '&m=' + month + '&d=' + day; + ret = ret + '\n=== <a href=' + url + ' target=\'_blank\'>' + date + '</a> ===' + '\n'; + logsByDate[date].forEach(log => { + ret = ret + log + '\n'; + }); + }); + return ret; +} + +function logProcess(text) { + text = ircAction(text); + text = escapeHtml(text); + text = aggrLog(text); + text = linkify(text); + return text; +} + +function loadLog() { + if (query === '') return; + let targetUrl = 'https://raye.mistivia.com/cgi-bin/irclogsearch/?' + encodeURIComponent(query); + fetch(targetUrl) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP Error: ${response.status} ${response.statusText} for hash: ${urlHash}`); + } + return response.text(); + }) + .then(text => { + logContainer.innerHTML = `<pre>${logProcess(text.trim())}</pre>`; + }) + .catch(error => { + console.error('Fetch error:', error); + logContainer.innerHTML = ''; + }); +} + +loadLog(); + +function search() { + query = queryInput.value.trim(); + window.history.replaceState(null, '', window.location.origin + window.location.pathname + '?q=' + encodeURIComponent(query)); + loadLog(); +} + +function handleEnter(event) { + if (event.key === 'Enter' || event.keyCode === 13) { + event.preventDefault(); + search(); + } +} + +queryInput.addEventListener('keyup', handleEnter);
\ No newline at end of file diff --git a/irclog/view/index.html b/irclog/view/index.html index ca76d66..3041286 100644 --- a/irclog/view/index.html +++ b/irclog/view/index.html @@ -7,7 +7,7 @@ <style> body { font-family: Arial, sans-serif; - max-width: 1000px; + max-width: 1200px; margin: 20px; background-color: #f4f4f4; } @@ -37,6 +37,9 @@ font-size: 0.7em; } } + #searchlink { + visibility: hidden; + } </style> </head> <body> @@ -46,14 +49,14 @@ <label for="log-date">选择日期:</label> <input type="date" id="log-date" value=""> <button onclick="setToday()">今天</button> - <br> - <br> + <br> + <span id="searchlink"><br><button onclick="gotosearch()">搜索</button><br><br></span> </div> <button onclick="setPreviousDay()">上一天</button> <button onclick="setNextDay()">下一天</button> <div id="log-container"></div> <button onclick="setPreviousDay()">上一天</button> <button onclick="setNextDay()">下一天</button> - <script src="./view.js"></script> + <script src="./view1.js"></script> </body> </html> diff --git a/irclog/view/view.js b/irclog/view/view1.js index eb98af0..567ec23 100644 --- a/irclog/view/view.js +++ b/irclog/view/view1.js @@ -8,6 +8,10 @@ let year = urlParams.get('y'); let month = urlParams.get('m'); let day = urlParams.get('d'); +if (chan === 'main') { + document.getElementById('searchlink').style.visibility = 'visible'; +} + function getDate(year, month, day) { try { year = parseInt(year, 10); @@ -140,4 +144,8 @@ function setToday() { let date = getDate('', '', ''); setDateState(date); dateInput.dispatchEvent(new Event('change')); +} + +function gotosearch() { + window.open('../search/', '_blank'); }
\ No newline at end of file |
