Support keword

This commit is contained in:
2025-09-24 03:38:32 +08:00
parent a4891b1c30
commit 8592833d74
16 changed files with 2888 additions and 2 deletions

View File

@@ -0,0 +1,84 @@
/**
* 爬取任务操作JavaScript
*/
function startTask(taskId) {
if (confirm('确定要启动这个任务吗?')) {
fetch(`/admin/core/crawltask/${taskId}/start/`, {
method: 'POST',
headers: {
'X-CSRFToken': getCookie('csrftoken'),
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(response => {
if (response.ok) {
location.reload();
} else {
alert('启动任务失败');
}
})
.catch(error => {
console.error('Error:', error);
alert('启动任务失败');
});
}
}
function cancelTask(taskId) {
if (confirm('确定要取消这个任务吗?')) {
fetch(`/admin/core/crawltask/${taskId}/cancel/`, {
method: 'POST',
headers: {
'X-CSRFToken': getCookie('csrftoken'),
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(response => {
if (response.ok) {
location.reload();
} else {
alert('取消任务失败');
}
})
.catch(error => {
console.error('Error:', error);
alert('取消任务失败');
});
}
}
function viewResults(taskId) {
window.open(`/admin/core/crawltask/${taskId}/results/`, '_blank');
}
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
// 自动刷新运行中的任务状态
function autoRefreshRunningTasks() {
const runningTasks = document.querySelectorAll('[data-task-status="running"]');
if (runningTasks.length > 0) {
// 每30秒刷新一次页面
setTimeout(() => {
location.reload();
}, 30000);
}
}
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
autoRefreshRunningTasks();
});