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 const setDisabled = function(value: boolean) {
28 acceptAll.disabled = value;
29 declineAll.disabled = value;
30 };
31
32 if (firstPage.length == 0) {
33 setDisabled(true);
34 } else {
35 acceptAll.addEventListener('click', async () => {
36 setDisabled(true);
37
38 const ids = await api.iterate('internal', 'friends/requests?page=', 1);
39 const payloads = ids.map((request: any) => ({
40 method: 'POST',
41 headers: {
42 'Content-Type': 'application/json'
43 },
44 body: JSON.stringify({
45 userID: request.senderID
46 })
47 }));
48 api.batchAction('friends/send', payloads);
49 });
50
51 declineAll.addEventListener('click', async () => {
52 setDisabled(true);
53
54 const ids = await api.iterate('internal', 'friends/requests?page=', 1);
55 const payloads = ids.map((request: any) => ({
56 method: 'POST',
57 headers: {
58 'Content-Type': 'application/json'
59 },
60 body: JSON.stringify({
61 userID: request.senderID
62 })
63 }));
64 api.batchAction('friends/remove', payloads);
65 });
66 };
67
68 container.parentElement!.insertBefore(actionBtns, container);
69};
70
71export function checkboxes() {};