diff options
| author | Mistivia <i@mistivia.com> | 2025-11-04 22:34:33 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-04 22:34:33 +0800 |
| commit | 6c66b7c72013f8e335d93b28e743101883f30bb9 (patch) | |
| tree | 38d257a068361bb31456f5cd85bb69e4b4538783 /irclog/search/search.js | |
| parent | cb63d6de3d3e8b747bf1b178190a183b9ab4a506 (diff) | |
add scroll to log line
Diffstat (limited to 'irclog/search/search.js')
| -rw-r--r-- | irclog/search/search.js | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/irclog/search/search.js b/irclog/search/search.js deleted file mode 100644 index 9a574d6..0000000 --- a/irclog/search/search.js +++ /dev/null @@ -1,112 +0,0 @@ -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 |
