| <!DOCTYPE html> |
| <html lang="fa" dir="rtl"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
| <title>جستجوگر متن موبایل</title> |
| <style> |
| * { |
| box-sizing: border-box; |
| outline: none; |
| } |
| |
| body { |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; |
| background-color: #f0f2f5; |
| margin: 0; |
| padding: 0; |
| color: #333; |
| font-size: 16px; |
| } |
| |
| .header { |
| background-color: #ffffff; |
| padding: 15px; |
| text-align: center; |
| box-shadow: 0 2px 5px rgba(0,0,0,0.05); |
| position: sticky; |
| top: 0; |
| z-index: 100; |
| } |
| |
| .header h1 { |
| margin: 0; |
| font-size: 18px; |
| color: #444; |
| } |
| |
| .container { |
| padding: 15px; |
| max-width: 600px; |
| margin: 0 auto; |
| } |
| |
| label { |
| display: block; |
| margin-bottom: 8px; |
| font-weight: bold; |
| font-size: 14px; |
| color: #555; |
| } |
| |
| |
| textarea { |
| width: 100%; |
| height: 150px; |
| padding: 12px; |
| border: 1px solid #ddd; |
| border-radius: 12px; |
| font-family: inherit; |
| font-size: 16px; |
| resize: vertical; |
| background: #fff; |
| transition: border-color 0.3s; |
| } |
| |
| textarea:focus { |
| border-color: #007bff; |
| } |
| |
| |
| .search-area { |
| background: white; |
| padding: 15px; |
| border-radius: 12px; |
| margin-top: 15px; |
| box-shadow: 0 2px 8px rgba(0,0,0,0.05); |
| } |
| |
| input[type="text"] { |
| width: 100%; |
| padding: 12px; |
| border: 1px solid #ddd; |
| border-radius: 8px; |
| font-family: inherit; |
| font-size: 16px; |
| margin-bottom: 10px; |
| } |
| |
| button { |
| width: 100%; |
| padding: 14px; |
| background-color: #007bff; |
| color: white; |
| border: none; |
| border-radius: 8px; |
| font-size: 16px; |
| font-weight: bold; |
| cursor: pointer; |
| transition: background 0.2s; |
| |
| touch-action: manipulation; |
| } |
| |
| button:active { |
| background-color: #0056b3; |
| transform: scale(0.98); |
| } |
| |
| |
| #result-wrapper { |
| margin-top: 20px; |
| display: none; |
| } |
| |
| .result-title { |
| font-size: 14px; |
| color: #666; |
| margin-bottom: 5px; |
| display: flex; |
| justify-content: space-between; |
| } |
| |
| #result-box { |
| background: #fff; |
| padding: 15px; |
| border-radius: 12px; |
| line-height: 2; |
| border: 2px solid #007bff; |
| min-height: 100px; |
| white-space: pre-wrap; |
| } |
| |
| .highlight { |
| background-color: #ffeb3b; |
| color: #000; |
| padding: 2px 4px; |
| border-radius: 4px; |
| font-weight: bold; |
| box-shadow: 0 1px 2px rgba(0,0,0,0.1); |
| } |
| |
| .error-msg { |
| color: red; |
| font-size: 13px; |
| margin-top: 5px; |
| display: none; |
| } |
| |
| </style> |
| </head> |
| <body> |
|
|
| <div class="header"> |
| <h1>جستجوگر متن پیشرفته</h1> |
| </div> |
|
|
| <div class="container"> |
| |
| |
| <label for="mainText">۱. متن اصلی را اینجا وارد کنید:</label> |
| <textarea id="mainText" placeholder="متن طولانی خود را اینجا پیست کنید یا بنویسید..."></textarea> |
|
|
| |
| <div class="search-area"> |
| <label for="searchQuery">۲. دنبال چه کلمهای هستید؟</label> |
| <input type="text" id="searchQuery" placeholder="مثلاً: سلام"> |
| <button onclick="doSearch()">جستجو و نمایش نتیجه</button> |
| <div id="errorMsg" class="error-msg">لطفا هم متن اصلی و هم کلمه جستجو را وارد کنید.</div> |
| </div> |
|
|
| |
| <div id="result-wrapper"> |
| <div class="result-title"> |
| <span>نتیجه جستجو:</span> |
| <span id="count-badge">0 مورد</span> |
| </div> |
| <div id="result-box"></div> |
| </div> |
|
|
| </div> |
|
|
| <script> |
| function doSearch() { |
| |
| const mainText = document.getElementById('mainText').value; |
| const query = document.getElementById('searchQuery').value; |
| const resultWrapper = document.getElementById('result-wrapper'); |
| const resultBox = document.getElementById('result-box'); |
| const countBadge = document.getElementById('count-badge'); |
| const errorMsg = document.getElementById('errorMsg'); |
| |
| |
| if (!mainText.trim() || !query.trim()) { |
| errorMsg.style.display = 'block'; |
| resultWrapper.style.display = 'none'; |
| return; |
| } |
| |
| errorMsg.style.display = 'none'; |
| resultWrapper.style.display = 'block'; |
| |
| |
| |
| const safeQuery = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| |
| |
| |
| |
| const regex = new RegExp(`(${safeQuery})`, 'gi'); |
| |
| |
| |
| const highlightedText = mainText.replace(regex, '<span class="highlight">$1</span>'); |
| |
| |
| resultBox.innerHTML = highlightedText; |
| |
| |
| const count = (mainText.match(regex) || []).length; |
| countBadge.innerText = count + " مورد پیدا شد"; |
| |
| |
| resultWrapper.scrollIntoView({ behavior: 'smooth' }); |
| } |
| </script> |
|
|
| </body> |
| </html> |