A rewrite of Poly+, my quality-of-life browser extension for Polytoria. Built entirely fresh using the WXT extension framework, Typescript, and with added better overall code quality.
extension
1import * as api from "@/utils/api"; 2 3export function actions() { 4 const container = document.getElementById('friends-container')!; 5 6 const actionBtns = document.createElement('div'); 7 actionBtns.classList.add('row', 'mb-3'); 8 actionBtns.innerHTML = ` 9 <div class="col"> 10 <button class="btn btn-success w-100"> 11 Accept All 12 </button> 13 </div> 14 <div class="col"> 15 <button class="btn btn-danger w-100"> 16 Decline All 17 </button> 18 </div> 19 `; 20 21 const acceptAll: HTMLButtonElement = actionBtns.querySelector('.btn-success')!; 22 const declineAll: HTMLButtonElement = actionBtns.querySelector('.btn-danger')!; 23 24 const firstPage = Array.from(container.getElementsByTagName('a')) 25 .map((link) => link.getAttribute('href')?.split('/')[2]); 26 27 //api.iterate('internal', '/friends?page=', 1).then(data => console.log(data)) 28 29 const setDisabled = function(value: boolean) { 30 acceptAll.disabled = value; 31 declineAll.disabled = value; 32 }; 33 34 if (firstPage.length == 0) { 35 setDisabled(true); 36 } else { 37 acceptAll.addEventListener('click', async () => { 38 setDisabled(true); 39 40 const ids = await api.iterate('internal', '/friends/requests?page=', 1); 41 const payloads = ids.map((request: any) => ({ 42 method: 'POST', 43 headers: { 44 'Content-Type': 'application/json' 45 }, 46 body: JSON.stringify({ 47 userID: request.senderID 48 }) 49 })); 50 api.batchAction('/friends/send', payloads); 51 }); 52 53 declineAll.addEventListener('click', async () => { 54 setDisabled(true); 55 56 const ids = await api.iterate('internal', '/friends/requests?page=', 1); 57 const payloads = ids.map((request: any) => ({ 58 method: 'POST', 59 headers: { 60 'Content-Type': 'application/json' 61 }, 62 body: JSON.stringify({ 63 userID: request.senderID 64 }) 65 })); 66 api.batchAction('/friends/remove', payloads); 67 }); 68 }; 69 70 container.parentElement!.insertBefore(actionBtns, container); 71}; 72 73export function checkboxes() {};