import { escape, whenReady } from './dom'; import { DataTable, dumbFilterCallback } from './data_tables'; import { globalSetup } from './main'; const parsePasteInfo = (elem) => { if (!elem.dataset.pasteInfo) { return null; } return JSON.parse(elem.dataset.pasteInfo); }; whenReady(() => { globalSetup(); const urlParams = new URLSearchParams(window.location.search); const myParam = urlParams.get('q'); const table = new DataTable(document.getElementById('archive'), { reverseRowCallback: parsePasteInfo, rowCallback: (rowData) => { const tags = rowData.tags.map((tagData) => { let tagColorClass; if (tagData.name.indexOf('nsfw') !== -1) { tagColorClass = 'is-danger'; } else if (tagData.name.indexOf('safe') !== -1) { tagColorClass = 'is-success'; } else if (tagData.name.indexOf('/') !== -1) { tagColorClass = 'is-primary'; } else { tagColorClass = 'is-info'; } return ` ${escape(tagData.name)} `; }).join(''); return ` ${escape(rowData.title)} ${rowData.created_at} ${rowData.visibility} ${rowData.views || 0} ${tags} `; }, filterCallback: dumbFilterCallback, preFilter: myParam }); table.attach(); const faveTable = new DataTable(document.getElementById('favs'), { reverseRowCallback: parsePasteInfo, rowCallback: (rowData) => { const tags = rowData.tags.map((tagData) => { let tagColorClass; if (tagData.name.indexOf('nsfw') !== -1) { tagColorClass = 'is-danger'; } else if (tagData.name.indexOf('safe') !== -1) { tagColorClass = 'is-success'; } else if (tagData.name.indexOf('/') !== -1) { tagColorClass = 'is-primary'; } else { tagColorClass = 'is-info'; } return ` ${escape(tagData.name)} `; }).join(''); const recentUpdate = rowData.recently_updated ? `` : ``; // ${escape(rowData.author)} return ` ${escape(rowData.title)} ${rowData.favourited_at} ${recentUpdate} ${tags} `; }, filterCallback: dumbFilterCallback, preFilter: myParam }); faveTable.attach(); });