-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
50 lines (42 loc) · 1.44 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
declare const GM_addElement: any
declare const Notyf: any
GM_addElement('link', { rel: 'stylesheet', href: 'https://unpkg.com/[email protected]/notyf.min.css' })
GM_addElement('script', { src: 'https://unpkg.com/[email protected]/notyf.min.js' })
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
let notyf: any
const deleteDeploys = async function (id: string) {
try {
return fetch(`https://vercel.com/api/v2/deployments/dpl_${id}`, {
method: 'DELETE',
mode: 'cors',
credentials: 'include',
})
} catch (e) {
notyf.open({ type: 'error', message: `Delete error: ${e}`, duration: 0 })
}
}
GM_registerMenuCommand('Delete deploys', async () => {
// eslint-disable-next-line no-alert
const answer = confirm('Confirm delete?')
if (!answer) return
notyf = new Notyf({
duration: 0,
position: { x: 'right', y: 'top' },
types: [{ type: 'info', background: 'blueviolet', icon: false }],
})
const arr = document.querySelectorAll('.deployment-entity')
if (!arr) return
for (const it of arr) {
const h = it.innerHTML
if (h.includes('Current')) continue
const id = h.match(/<a.*href=".*\/(\w+)">.*<\/a>/)?.[1]
notyf.open({ type: 'info', message: `Deleting ${id}` })
if (id) await deleteDeploys(id)
await sleep(1000)
notyf.dismissAll()
}
notyf.open({ type: 'success', message: 'Delete finished.', duration: 1000 })
setTimeout(() => {
location.reload()
}, 1000)
})