mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-04-23 06:15:09 +00:00
Larger refactoring and added avoidlist
This commit is contained in:
48
client/web/scripts/avoid-form.js
Normal file
48
client/web/scripts/avoid-form.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { updateAvoidList } from './avoid-list.js';
|
||||
|
||||
const avoidForm = document.getElementById('avoidForm');
|
||||
if (avoidForm) {
|
||||
avoidForm.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
const user = document.getElementById('avoidUser').value;
|
||||
|
||||
if(!user)
|
||||
return;
|
||||
|
||||
fetch('/avoidlist', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user
|
||||
}),
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then((data) => {
|
||||
updateAvoidList();
|
||||
document.getElementById('avoidUser').value = '';
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
});
|
||||
|
||||
const removeUser = document.getElementById('removeUser');
|
||||
if(removeUser){
|
||||
document.getElementById('removeUser').addEventListener('click', function () {
|
||||
const user = document.getElementById('avoidUser').value;
|
||||
|
||||
fetch(`/avoidlist/${user}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
.then(_ => {
|
||||
updateAvoidList();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user