Спасибо всем!
ниже приведены основные функциональные коды инструмента.
Первый раз задание вопроса о программировании, подобном этому, и особенно на такой платформе. Если у меня есть ошибка в отображении вопроса, пожалуйста, помогите мне исправить его. Спасибо! < /P>
window.addEventListener('load', function() {
loadSavedUrls();
updateUrlDisplay();
updateActiveTasksDisplay();
updateTimezoneDisplay();
updateCalendar();
const now = new Date();
const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);
document.getElementById('scheduleDate').value = tomorrow.toISOString().split('T')[0];
document.getElementById('scheduleTime').value = '09:00';
});
setInterval(() => {
if (activeTasks.length === 0) refreshApp();
}, 4 * 60 * 60 * 1000);
setInterval(updateTimezoneDisplay, 1000);
< /code>
🗂 Метод переключения и планирования вкладок < /p>
function switchTab(tabName) {
document.querySelectorAll('.tab-content').forEach(tab => tab.classList.remove('active'));
document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
document.getElementById(tabName).classList.add('active');
event.target.classList.add('active');
}
function selectMethod(method) {
currentSchedulingMethod = method;
document.querySelectorAll('.method-option').forEach(option => option.classList.remove('active'));
event.target.classList.add('active');
document.getElementById('delaySection').style.display = method === 'delay' ? 'block' : 'none';
document.getElementById('datetimeSection').classList.toggle('active', method === 'datetime');
updateScheduleButtonText();
}
function updateScheduleButtonText() {
const btn = document.getElementById('scheduleBtn');
btn.textContent = currentSchedulingMethod === 'delay'
? 'placeholder'
: 'placeholder';
}
< /code>
function updateCalendar() {
const calendarGrid = document.getElementById('calendarGrid');
const calendarTitle = document.getElementById('calendarTitle');
const year = currentCalendarDate.getFullYear();
const month = currentCalendarDate.getMonth();
calendarTitle.textContent = new Date(year, month).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
calendarGrid.innerHTML = '';
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].forEach(day => {
const header = document.createElement('div');
header.className = 'calendar-day-header';
header.textContent = day;
calendarGrid.appendChild(header);
});
const firstDay = new Date(year, month, 1);
const lastDay = new Date(year, month + 1, 0);
const startingDayOfWeek = firstDay.getDay();
const daysInMonth = lastDay.getDate();
for (let i = 0; i < startingDayOfWeek; i++) {
const emptyDay = document.createElement('div');
emptyDay.className = 'calendar-day other-month';
emptyDay.textContent = new Date(year, month, 0 - (startingDayOfWeek - 1 - i)).getDate();
calendarGrid.appendChild(emptyDay);
}
const today = new Date();
for (let day = 1; day selectCalendarDate(currentDate);
calendarGrid.appendChild(dayElement);
}
const totalCells = calendarGrid.children.length - 7;
const remainingCells = 42 - totalCells;
for (let day = 1; day
function addUrl() {
const urlInput = document.getElementById('newUrl');
const url = formatUrl(urlInput.value.trim());
if (!url || savedUrls.includes(url)) return showStatus('Invalid or duplicate URL', 'error');
savedUrls.push(url);
urlInput.value = '';
updateUrlDisplay();
saveUrls();
showStatus('URL added successfully', 'success');
}
function addBulkUrls() {
const urls = document.getElementById('bulkUrls').value.split('\n').filter(url => url.trim());
let addedCount = 0;
urls.forEach(url => {
const formatted = formatUrl(url.trim());
if (formatted && !savedUrls.includes(formatted)) {
savedUrls.push(formatted);
addedCount++;
}
});
document.getElementById('bulkUrls').value = '';
updateUrlDisplay();
saveUrls();
showStatus(`Added ${addedCount} URLs successfully`, 'success');
}
function removeUrl(index) {
savedUrls.splice(index, 1);
updateUrlDisplay();
saveUrls();
showStatus('URL removed', 'success');
}
function clearAllUrls() {
if (confirm('Are you sure you want to clear all saved URLs?')) {
savedUrls = [];
updateUrlDisplay();
saveUrls();
showStatus('All URLs cleared', 'success');
}
}
function exportUrls() {
if (savedUrls.length === 0) return showStatus('No URLs to export', 'error');
const dataStr = JSON.stringify(savedUrls, null, 2);
const blob = new Blob([dataStr], { type: 'application/json' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'danh-sach-urls.json';
link.click();
URL.revokeObjectURL(link.href);
showStatus('URLs exported successfully', 'success');
}
function importUrls() {
document.getElementById('fileInput').click();
}
function handleFileImport(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const imported = JSON.parse(e.target.result);
if (Array.isArray(imported)) {
let count = 0;
imported.forEach(url => {
if (typeof url === 'string' && !savedUrls.includes(url)) {
savedUrls.push(url);
count++;
}
});
updateUrlDisplay();
saveUrls();
showStatus(`Imported ${count} URLs`, 'success');
} else {
throw new Error();
}
} catch {
const lines = e.target.result.split('\n');
let count = 0;
lines.forEach(line => {
const url = formatUrl(line.trim());
if (url && !savedUrls.includes(url)) {
savedUrls.push(url);
count++;
}
});
updateUrlDisplay();
saveUrls();
showStatus(count > 0 ? `Imported ${count} URLs` : 'No valid URLs found', count > 0 ? 'success' : 'error');
}
};
reader.readAsText(file);
}
< /code>
document.getElementById('schedulerForm').addEventListener('submit', function(e) {
e.preventDefault();
const url = formatUrl(document.getElementById('singleUrl').value.trim());
if (!url) return showStatus('Chưa Nhập URLs', 'error');
if (currentSchedulingMethod === 'delay') {
const delayAmount = parseInt(document.getElementById('delayAmount').value);
const delayUnit = document.getElementById('delayUnit').value;
const delayMs = convertToMilliseconds(delayAmount, delayUnit);
scheduleUrl(url, delayMs, delayAmount, delayUnit, 'delay');
} else {
const date = document.getElementById('scheduleDate').value;
const time = document.getElementById('scheduleTime').value;
const tz = document.getElementById('timezoneSelect').value;
if (!date || !time) return showStatus('Please select both date and time', 'error');
const target = createTargetDateTime(date, time, tz);
if (target scheduleUrl(url, ms, amount, unit, 'delay'));
} else {
const date = document.getElementById('scheduleDate').value;
const time = document.getElementById('scheduleTime').value;
const tz = document.getElementById('timezoneSelect').value;
const target = createTargetDateTime(date, time, tz);
if (target {
scheduleUrl(url, ms + i * 1000, null, null, 'datetime', new Date(target.getTime() + i * 1000));
});
}
}
function launchAllUrls() {
if (savedUrls.length === 0) return showStatus('No saved URLs to launch', 'error');
savedUrls.forEach(url => setTimeout(() => launchUrl(url), Math.random() * 1000));
showStatus(`Launching ${savedUrls.length} URLs...`, 'success');
}
function scheduleUrl(url, delayMs, delayAmount, delayUnit, method, targetDateTime = null) {
const taskId = ++taskIdCounter;
const task = {
id: taskId, url, startTime: Date.now(), endTime: Date.now() + delayMs,
delayAmount, delayUnit, method, targetDateTime
};
task.timeout = setTimeout(() => {
wakeSystem();
setTimeout(() => {
launchUrl(url);
removeTask(taskId);
}, 500);
}, delayMs);
activeTasks.push(task);
updateActiveTasksDisplay();
const msg = method === 'delay'
? `Scheduled ${url} to launch in ${delayAmount} ${delayUnit}`
: `Scheduled ${url} to launch at ${targetDateTime.toLocaleString()}`;
showStatus(msg, 'success');
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... pp-not-wor