import { URL_SCHEMES, MESSAGES, RESOURCE_CONFIGS } from './config.js'; // URL验证函数 function validateUrl(url) { try { new URL(url); return true; } catch (error) { return false; } } // 显示错误信息 function showError(message) { const errorEl = document.getElementById('errorMessage'); errorEl.textContent = message; setTimeout(() => { errorEl.textContent = ''; }, 3000); } // 安装资源 function installResource(isSpecial, configUrl = null) { const urlInput = document.getElementById('customUrl'); let url = configUrl || urlInput.value.trim(); if (!url) { showError(MESSAGES.EMPTY_URL); return; } if (!validateUrl(url)) { showError(MESSAGES.INVALID_URL); return; } const encodedUrl = encodeURIComponent(url); const finalUrl = isSpecial ? `${URL_SCHEMES.INTENT}${encodedUrl}#Intent;scheme=uzVideo;end` : `${URL_SCHEMES.BASE}${encodedUrl}`; window.location.href = finalUrl; } // 复制到剪贴板 async function copyToClipboard(text) { try { if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); } else { const textArea = document.createElement('textarea'); textArea.value = text; textArea.style.position = 'fixed'; textArea.style.left = '-9999px'; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); } catch (err) { console.error('复制失败:', err); throw err; } finally { document.body.removeChild(textArea); } } alert(MESSAGES.COPY_SUCCESS + '\n' + MESSAGES.USAGE_PATH); } catch (err) { console.error('复制操作失败:', err); alert(MESSAGES.COPY_FAIL + text); } } // 创建资源卡片 function createResourceCard(config) { const resourceGroup = document.createElement('div'); resourceGroup.className = 'resource-group'; resourceGroup.innerHTML = `