Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Exception Quiz</title>
- <style>
- table {
- width: 100%;
- border-collapse: collapse;
- }
- th, td {
- padding: 8px;
- text-align: left;
- border: 1px solid #ddd;
- }
- th {
- background-color: #f4f4f4;
- cursor: pointer;
- }
- input[type="text"] {
- width: 100%;
- padding: 8px;
- margin-bottom: 10px;
- box-sizing: border-box;
- }
- </style>
- </head>
- <body>
- <h1>List of Links</h1>
- <input type="text" id="searchInput" placeholder="Search Links...">
- <table>
- <thead>
- <tr>
- <th onclick="sortTable(0)">Title</th>
- <th onclick="sortTable(1)">Description</th>
- <th onclick="sortTable(2)">Link</th>
- </tr>
- </thead>
- <tbody id="tableBody">
- <!-- Data will be populated here -->
- </tbody>
- </table>
- <script>
- const url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vSqLkeyCxbcIBCnCEY4nIltdFjDAE4etzIhwh8BB3RKsZUoUWDDG_sm49ayjbWCRpG6mWIsCbICoSrR/pub?gid=1919940108&single=true&output=tsv';
- document.addEventListener('DOMContentLoaded', () => {
- fetch(url)
- .then(response => response.text())
- .then(data => {
- const rows = data.trim().split('\n');
- const tableBody = document.getElementById('tableBody');
- rows.slice(1).forEach(row => {
- const cols = row.split('\t');
- const tr = document.createElement('tr');
- cols.forEach((col, index) => {
- const td = document.createElement('td');
- if (index === 2) {
- const a = document.createElement('a');
- a.href = col;
- a.textContent = col;
- a.target = "_blank";
- td.appendChild(a);
- } else {
- td.textContent = col;
- }
- tr.appendChild(td);
- });
- tableBody.appendChild(tr);
- });
- document.getElementById('searchInput').addEventListener('input', filterTable);
- });
- });
- function filterTable() {
- const input = document.getElementById('searchInput');
- const filter = input.value.toLowerCase();
- const table = document.querySelector('table');
- const trs = table.getElementsByTagName('tr');
- for (let i = 1; i < trs.length; i++) {
- trs[i].style.display = trs[i].innerText.toLowerCase().includes(filter) ? '' : 'none';
- }
- }
- function sortTable(n) {
- const table = document.querySelector('table');
- let rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
- switching = true;
- dir = "asc";
- while (switching) {
- switching = false;
- rows = table.rows;
- for (i = 1; i < (rows.length - 1); i++) {
- shouldSwitch = false;
- x = rows[i].getElementsByTagName("TD")[n];
- y = rows[i + 1].getElementsByTagName("TD")[n];
- if (dir == "asc") {
- if (x.textContent.toLowerCase() > y.textContent.toLowerCase()) {
- shouldSwitch = true;
- break;
- }
- } else if (dir == "desc") {
- if (x.textContent.toLowerCase() < y.textContent.toLowerCase()) {
- shouldSwitch = true;
- break;
- }
- }
- }
- if (shouldSwitch) {
- rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
- switching = true;
- switchcount++;
- } else {
- if (switchcount == 0 && dir == "asc") {
- dir = "desc";
- switching = true;
- }
- }
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment