@copoko/space
Version:
CoPoKo Space
198 lines • 5.76 kB
HTML
<script>
function Subscribe(it) {
const rss_input = document.getElementById("rss-input").value;
if (!rss_input) {
return;
}
fetch(`/space/api/RSSSUB/add`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: rss_input
})
}).then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
if (json.success) {
rendererRSSCtrlList()
Toast.fire({
icon: 'success',
title: `Add RSS Successfully`
})
}
}).catch(function (error) {
console.log(error);
Toast.fire({
icon: 'error',
title: `Add RSS Failed`
})
});
}
function getRSSCtrlItem(it) {
const on = `<span class="badge badge-success">ON</span>`;
const off = `<span class="badge badge-danger">OFF</span></a>`;
return `<tr>
<td><a href="${it.url}" target="_blank" rel="noopener noreferrer">${it.title}</a></td>
<td><a url="${it.url}" onclick="changeStatus(this)" href="#">${it.status ? on : off}</a></td>
<td><a url="${it.url}" onclick="changeNotify(this)" href="#">${it.notify ? on : off}</a></td>
<td class="project-actions text-right">
<a url="${it.url}" onclick="DeleteCtrlItem(this)" class="btn btn-danger btn-sm">
<i class="fas fa-trash"> </i>
Delete
</a>
</td>
</tr>`
}
function rendererRSSCtrlList() {
fetch("/space/api/RSSSUB/").then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
let rss_list = document.getElementById("rss-ctrl-list");
rss_list.innerHTML = "";
json.forEach(function (it) {
let rss_item = getRSSCtrlItem(it)
rss_list.innerHTML += rss_item;
});
rendererRSSResult();
}).catch(function (error) {
console.log(error);
});
}
rendererRSSCtrlList()
function DeleteCtrlItem(it) {
const url = it.getAttribute("url");
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
fetch(`/space/api/RSSSUB/delete`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: url
})
}).then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
if (json.success) {
rendererRSSCtrlList()
Toast.fire({
icon: 'success',
title: `Delete RSS Successfully`
})
}
}).catch(function (error) {
console.log(error);
Toast.fire({
icon: 'error',
title: `Delete RSS Failed`
})
});
}
})
}
function changeStatus(it) {
fetch(`/space/api/RSSSUB/status`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: it.getAttribute("url")
})
}).then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
if (json.success) {
rendererRSSCtrlList()
Toast.fire({
icon: 'success',
title: `Change Status Successfully`
})
}
}).catch(function (error) {
console.log(error);
Toast.fire({
icon: 'error',
title: `Change Status Failed`
})
});
return false;
}
function changeNotify(it) {
fetch(`/space/api/RSSSUB/notify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: it.getAttribute("url")
})
}).then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
if (json.success) {
rendererRSSCtrlList()
Toast.fire({
icon: 'success',
title: `Change Notify Successfully`
})
}
}).catch(function (error) {
console.log(error);
Toast.fire({
icon: 'error',
title: `Change Notify Failed`
})
});
return false;
}
function rendererRSSResult() {
fetch("/space/api/RSSSUB/").then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
let rss_list = document.getElementById("rss-result-list");
rss_list.innerHTML = "";
json.forEach(function (it) {
let rss_item = getRSSResultItem(it)
rss_list.innerHTML += rss_item;
});
}).catch(function (error) {
console.log(error);
});
}
function getRSSResultItem(it) {
return `<div class="list-group-item">
<div class="row">
<div class="col px-4">
<div>
<a href="${it.url}" target="_blank" rel="noopener noreferrer"><h3>${it.title}</h3></a>
<a href="${it.lastLink}" target="_blank" rel="noopener noreferrer">
<span class="text-muted">${it.lastLink}</span>
</a>
<a href="${it.lastPostView}" target="_blank" rel="noopener noreferrer">
<p class="mb-0">${it.lastPost}</p>
</a>
</div>
</div>
</div>
</div>`;
}
fetch("/space/api/RSSSUB/update").catch(e => { })
</script>