forked from defunkt/toes
20 lines
668 B
TypeScript
20 lines
668 B
TypeScript
function toggleVisibility(btn: HTMLButtonElement) {
|
|
const repo = btn.dataset.repo!
|
|
const current = btn.dataset.visibility!
|
|
const next = current === 'public' ? 'private' : 'public'
|
|
btn.dataset.visibility = next
|
|
btn.textContent = next
|
|
btn.classList.toggle('public', next === 'public')
|
|
fetch('/api/visibility/' + encodeURIComponent(repo), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ visibility: next }),
|
|
}).catch(() => {
|
|
btn.dataset.visibility = current
|
|
btn.textContent = current
|
|
btn.classList.toggle('public', current === 'public')
|
|
})
|
|
}
|
|
|
|
Object.assign(window, { toggleVisibility })
|