|
| 1 | +const inputSearch = document.querySelector("#search-inp"); |
| 2 | +const tableDiv = document.querySelector("table"); |
| 3 | +const searchCount = document.querySelector("#searchCount"); |
| 4 | +const ownerLink = document.querySelector("#owner"); |
| 5 | + |
| 6 | +function numberWithCommas(x) { |
| 7 | + return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 8 | +} |
| 9 | + |
| 10 | +function main() { |
| 11 | + try { |
| 12 | + let data = JSON.parse(localStorage.ufs_fb_searchPageForOther) || []; |
| 13 | + let owner = JSON.parse(localStorage.ufs_fb_searchPageForOther_owner) || {}; |
| 14 | + console.log(data, owner); |
| 15 | + |
| 16 | + let link = "https://fb.com/" + owner.uid; |
| 17 | + ownerLink.innerHTML = ` |
| 18 | + <a href="${link}" target="_blank" style="display: inline-block;"> |
| 19 | + <img style="max-height: 80px;border-radius: 50%" src="${owner.avatar}" /> |
| 20 | + ${owner.name} |
| 21 | + </a>`; |
| 22 | + searchCount.innerHTML = data.length; |
| 23 | + |
| 24 | + tableDiv.innerHTML = ` |
| 25 | + <tr> |
| 26 | + <th>STT</th> |
| 27 | + <th>Ảnh</th> |
| 28 | + <th>Tên</th> |
| 29 | + </tr> |
| 30 | + ${data |
| 31 | + .map((c, i) => { |
| 32 | + return `<tr> |
| 33 | + <td>${i + 1}</td> |
| 34 | + <td><img src="${c.image}" style="max-height: 80px"></img></td> |
| 35 | + <td> |
| 36 | + <a style="font-size: 1.1em" href="${c.url}" target="_blank">${ |
| 37 | + c.name |
| 38 | + }</a> |
| 39 | + <br/> |
| 40 | + <span>${c.subTitle?.split?.("\n")?.[1] || ""}</span> |
| 41 | + </td> |
| 42 | + </tr>`; |
| 43 | + }) |
| 44 | + .join("")} |
| 45 | + `; |
| 46 | + |
| 47 | + inputSearch.oninput = (e) => { |
| 48 | + search(inputSearch.value); |
| 49 | + }; |
| 50 | + } catch (e) { |
| 51 | + alert("ERROR: " + e); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +function search(text) { |
| 56 | + let count = 0; |
| 57 | + [...tableDiv.querySelectorAll("tr")].forEach((tr, index) => { |
| 58 | + if (index == 0) return; // ignore table header |
| 59 | + |
| 60 | + let html = tr.innerHTML; |
| 61 | + if (!html.toLowerCase().includes(text.toLowerCase())) { |
| 62 | + tr.classList.add("hidden"); |
| 63 | + } else { |
| 64 | + tr.classList.remove("hidden"); |
| 65 | + count++; |
| 66 | + } |
| 67 | + }); |
| 68 | + searchCount.innerHTML = count; |
| 69 | +} |
| 70 | + |
| 71 | +main(); |
0 commit comments