more fixes

This commit is contained in:
Andrey Kondratev
2025-08-28 17:42:49 +05:00
parent 8213ca33e2
commit 3c615acaeb
14 changed files with 695 additions and 239 deletions

View File

@@ -2,36 +2,58 @@
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
<title>Quixotic Music</title>
<meta name="theme-color" content="#007AFF">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<link rel="stylesheet" href="style.css">
<script src="https://telegram.org/js/telegram-web-app.js"></script>
</head>
<body>
<div class="container">
<header>
<h1>🎵 Quixotic</h1>
<p>Найди и скачай музыку из YouTube</p>
</header>
<div class="search-section">
<div class="search-container">
<input type="text" id="searchInput" placeholder="Введите название песни..." autocomplete="off">
<button id="searchBtn">🔍</button>
<div class="tg-root">
<div class="tg-navigation">
<div class="tg-navigation__title">
<span class="tg-navigation__title-icon">🎵</span>
Quixotic
</div>
</div>
<div id="loading" class="loading hidden">
<div class="spinner"></div>
<p>Поиск...</p>
</div>
<div class="tg-content">
<div class="tg-placeholder" id="welcomePlaceholder">
<div class="tg-placeholder__icon">🎵</div>
<div class="tg-placeholder__title">Найти музыку</div>
<div class="tg-placeholder__description">Введите название песни или исполнителя для поиска на YouTube</div>
</div>
<div id="results" class="results-container">
<!-- Search results will appear here -->
</div>
<div class="tg-form">
<div class="tg-input-wrapper">
<input type="text"
class="tg-input"
id="searchInput"
placeholder="Название песни или исполнитель..."
autocomplete="off">
</div>
<button class="tg-button tg-button--primary tg-button--large" id="searchBtn">
<span class="tg-button__text">Найти</span>
</button>
</div>
<div id="noResults" class="no-results hidden">
<p>Ничего не найдено. Попробуйте другой запрос.</p>
<div class="tg-spinner" id="loading">
<div class="tg-spinner__icon"></div>
<div class="tg-spinner__text">Поиск музыки...</div>
</div>
<div class="tg-list" id="results">
<!-- Search results will appear here -->
</div>
<div class="tg-placeholder tg-placeholder--secondary" id="noResults">
<div class="tg-placeholder__icon">🔍</div>
<div class="tg-placeholder__title">Ничего не найдено</div>
<div class="tg-placeholder__description">Попробуйте изменить поисковый запрос</div>
</div>
</div>
</div>

View File

@@ -44,6 +44,7 @@ class QuixoticApp {
private loading!: HTMLElement;
private results!: HTMLElement;
private noResults!: HTMLElement;
private welcomePlaceholder!: HTMLElement;
constructor() {
this.tg = (window as WindowWithTelegram).Telegram?.WebApp;
@@ -63,6 +64,7 @@ class QuixoticApp {
this.loading = document.getElementById('loading') as HTMLElement;
this.results = document.getElementById('results') as HTMLElement;
this.noResults = document.getElementById('noResults') as HTMLElement;
this.welcomePlaceholder = document.getElementById('welcomePlaceholder') as HTMLElement;
}
private bindEvents(): void {
@@ -105,14 +107,17 @@ class QuixoticApp {
}
private showLoading(): void {
this.loading.classList.remove('hidden');
this.results.classList.add('hidden');
this.noResults.classList.add('hidden');
this.welcomePlaceholder.classList.add('tg-hidden');
this.loading.classList.remove('tg-hidden');
this.loading.classList.add('tg-spinner--visible');
this.results.classList.remove('tg-list--visible');
this.noResults.classList.add('tg-hidden');
this.searchBtn.disabled = true;
}
private hideLoading(): void {
this.loading.classList.add('hidden');
this.loading.classList.add('tg-hidden');
this.loading.classList.remove('tg-spinner--visible');
this.searchBtn.disabled = false;
}
@@ -125,31 +130,38 @@ class QuixoticApp {
}
this.results.innerHTML = videos.map(video => `
<div class="video-item" onclick="app.convertVideo('${video.id}', '${this.escapeHtml(video.title)}', '${this.escapeHtml(video.url)}')">
<img class="video-thumbnail" src="${video.thumbnail}" alt="${this.escapeHtml(video.title)}" loading="lazy">
<div class="video-info">
<div class="video-title">${this.escapeHtml(video.title)}</div>
<div class="video-channel">${this.escapeHtml(video.channel)}</div>
<div class="video-duration">${this.formatDuration(video.duration)}</div>
<div class="tg-list-item" onclick="app.convertVideo('${video.id}', '${this.escapeHtml(video.title)}', '${this.escapeHtml(video.url)}')">
<div class="tg-list-item__content">
<div class="tg-list-item__media">
<img class="tg-list-item__thumbnail"
src="${video.thumbnail}"
alt="${this.escapeHtml(video.title)}"
loading="lazy">
<div class="tg-list-item__duration">${this.formatDuration(video.duration)}</div>
</div>
<div class="tg-list-item__info">
<div class="tg-list-item__title">${this.escapeHtml(video.title)}</div>
<div class="tg-list-item__subtitle">${this.escapeHtml(video.channel)}</div>
</div>
</div>
</div>
`).join('');
this.results.classList.remove('hidden');
this.noResults.classList.add('hidden');
this.results.classList.add('tg-list--visible');
this.noResults.classList.add('tg-hidden');
}
private showNoResults(): void {
this.hideLoading();
this.results.classList.add('hidden');
this.noResults.classList.remove('hidden');
this.results.classList.remove('tg-list--visible');
this.noResults.classList.remove('tg-hidden');
}
public async convertVideo(videoId: string, title: string, url: string): Promise<void> {
console.log('Convert video called:', { videoId, title, url });
const videoElement = (event as any)?.currentTarget as HTMLElement;
if (videoElement) {
videoElement.classList.add('converting');
videoElement.classList.add('tg-list-item--converting');
}
try {
@@ -198,7 +210,6 @@ class QuixoticApp {
this.showMessage('✓ MP3 скачан!', 'success');
}
} else {
// Should not happen since we removed fallbacks
throw new Error('No audio URL received');
}
} catch (error: any) {
@@ -215,10 +226,10 @@ class QuixoticApp {
errorMsg = 'Видео заблокировано для скачивания.';
}
this.showMessage(`${errorMsg}`, 'warning');
this.showMessage(`${errorMsg}`, 'error');
} finally {
if (videoElement) {
videoElement.classList.remove('converting');
videoElement.classList.remove('tg-list-item--converting');
}
}
}
@@ -232,21 +243,18 @@ class QuixoticApp {
private showMessage(message: string, type: string = 'info'): void {
// Remove existing message if any
const existingMessage = document.querySelector('.status-message');
const existingMessage = document.querySelector('.tg-status-message');
if (existingMessage) {
existingMessage.remove();
}
// Create message element
const messageEl = document.createElement('div');
messageEl.className = `status-message status-${type}`;
messageEl.className = `tg-status-message tg-status-message--${type}`;
messageEl.textContent = message;
// Add to page
const container = document.querySelector('.container');
if (container) {
container.insertBefore(messageEl, container.firstChild);
}
// Add to body (fixed position, won't affect layout)
document.body.appendChild(messageEl);
// Auto-remove after 5 seconds
setTimeout(() => {

View File

@@ -1,245 +1,484 @@
/* Telegram Mini App Design System */
:root {
/* Telegram theme colors */
--tg-color-bg: var(--tg-theme-bg-color, #ffffff);
--tg-color-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
--tg-color-section-bg: var(--tg-theme-section-bg-color, #ffffff);
--tg-color-text: var(--tg-theme-text-color, #000000);
--tg-color-hint: var(--tg-theme-hint-color, #999999);
--tg-color-link: var(--tg-theme-link-color, #007aff);
--tg-color-button: var(--tg-theme-button-color, #007aff);
--tg-color-button-text: var(--tg-theme-button-text-color, #ffffff);
--tg-color-destructive: var(--tg-theme-destructive-text-color, #ff3b30);
/* Telegram dimensions */
--tg-border-radius: 12px;
--tg-border-radius-small: 8px;
--tg-spacing-xs: 4px;
--tg-spacing-sm: 8px;
--tg-spacing-md: 12px;
--tg-spacing-lg: 16px;
--tg-spacing-xl: 20px;
--tg-spacing-xxl: 24px;
/* Typography */
--tg-font-size-xs: 12px;
--tg-font-size-sm: 14px;
--tg-font-size-md: 16px;
--tg-font-size-lg: 17px;
--tg-font-size-xl: 20px;
--tg-font-size-xxl: 28px;
--tg-line-height-tight: 1.2;
--tg-line-height-normal: 1.4;
--tg-line-height-relaxed: 1.6;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
background: var(--tg-theme-bg-color, #f0f0f0);
color: var(--tg-theme-text-color, #000);
line-height: 1.6;
background: var(--tg-color-bg);
color: var(--tg-color-text);
font-size: var(--tg-font-size-md);
line-height: var(--tg-line-height-normal);
overflow-x: hidden;
}
.container {
max-width: 100vw;
margin: 0 auto;
padding: 20px 16px;
/* Root container */
.tg-root {
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
text-align: center;
margin-bottom: 30px;
/* Navigation */
.tg-navigation {
position: sticky;
top: 0;
z-index: 100;
background: var(--tg-color-bg);
border-bottom: 1px solid var(--tg-color-secondary-bg);
padding: var(--tg-spacing-lg);
}
header h1 {
font-size: 2rem;
margin-bottom: 8px;
color: var(--tg-theme-button-color, #007AFF);
.tg-navigation__title {
font-size: var(--tg-font-size-xl);
font-weight: 600;
color: var(--tg-color-text);
display: flex;
align-items: center;
gap: var(--tg-spacing-sm);
}
header p {
color: var(--tg-theme-hint-color, #666);
font-size: 0.9rem;
.tg-navigation__title-icon {
font-size: var(--tg-font-size-xxl);
}
.search-section {
margin-bottom: 30px;
/* Content area */
.tg-content {
flex: 1;
padding: var(--tg-spacing-lg);
display: flex;
flex-direction: column;
gap: var(--tg-spacing-xl);
}
.search-container {
display: flex;
gap: 10px;
background: var(--tg-theme-secondary-bg-color, #fff);
border-radius: 12px;
padding: 4px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
/* Form components */
.tg-form {
display: flex;
flex-direction: column;
gap: var(--tg-spacing-md);
}
#searchInput {
flex: 1;
padding: 12px 16px;
border: none;
background: transparent;
font-size: 1rem;
color: var(--tg-theme-text-color, #000);
outline: none;
.tg-input-wrapper {
position: relative;
}
#searchInput::placeholder {
color: var(--tg-theme-hint-color, #999);
.tg-input {
width: 100%;
height: 48px;
padding: 0 var(--tg-spacing-lg);
background: var(--tg-color-section-bg);
border: 2px solid var(--tg-color-secondary-bg);
border-radius: var(--tg-border-radius);
font-size: var(--tg-font-size-lg);
color: var(--tg-color-text);
transition: all 0.2s ease;
outline: none;
}
#searchBtn {
padding: 12px 16px;
background: var(--tg-theme-button-color, #007AFF);
color: var(--tg-theme-button-text-color, #fff);
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
transition: opacity 0.2s;
.tg-input::placeholder {
color: var(--tg-color-hint);
}
#searchBtn:hover {
opacity: 0.8;
.tg-input:focus {
border-color: var(--tg-color-button);
background: var(--tg-color-bg);
}
#searchBtn:disabled {
opacity: 0.5;
cursor: not-allowed;
/* Button components */
.tg-button {
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: var(--tg-spacing-sm);
border: none;
border-radius: var(--tg-border-radius);
font-family: inherit;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
outline: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.loading {
text-align: center;
padding: 40px 20px;
.tg-button--primary {
background: var(--tg-color-button);
color: var(--tg-color-button-text);
}
.spinner {
width: 40px;
height: 40px;
border: 3px solid var(--tg-theme-hint-color, #ddd);
border-top: 3px solid var(--tg-theme-button-color, #007AFF);
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 16px;
.tg-button--large {
height: 48px;
padding: 0 var(--tg-spacing-xl);
font-size: var(--tg-font-size-lg);
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
.tg-button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}
.results-container {
display: grid;
gap: 16px;
.tg-button:active:not(:disabled) {
transform: translateY(0);
}
.video-item {
display: flex;
background: var(--tg-theme-secondary-bg-color, #fff);
border-radius: 12px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
cursor: pointer;
position: relative;
.tg-button:disabled {
opacity: 0.4;
cursor: not-allowed;
transform: none !important;
box-shadow: none !important;
}
.video-item:hover {
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
.tg-button__text {
display: flex;
align-items: center;
gap: var(--tg-spacing-xs);
}
.video-thumbnail {
width: 120px;
height: 90px;
object-fit: cover;
flex-shrink: 0;
/* Placeholder component */
.tg-placeholder {
text-align: center;
padding: var(--tg-spacing-xxl) var(--tg-spacing-lg);
max-width: 300px;
margin: 0 auto;
}
.video-info {
padding: 16px;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
.tg-placeholder__icon {
font-size: 48px;
margin-bottom: var(--tg-spacing-lg);
opacity: 0.6;
}
.video-title {
font-weight: 600;
font-size: 0.95rem;
line-height: 1.4;
margin-bottom: 8px;
color: var(--tg-theme-text-color, #000);
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
.tg-placeholder__title {
font-size: var(--tg-font-size-xl);
font-weight: 600;
color: var(--tg-color-text);
margin-bottom: var(--tg-spacing-sm);
}
.video-channel {
font-size: 0.85rem;
color: var(--tg-theme-hint-color, #666);
margin-bottom: 4px;
.tg-placeholder__description {
font-size: var(--tg-font-size-sm);
color: var(--tg-color-hint);
line-height: var(--tg-line-height-relaxed);
}
.video-duration {
font-size: 0.8rem;
color: var(--tg-theme-hint-color, #888);
background: rgba(0, 0, 0, 0.1);
padding: 2px 6px;
border-radius: 4px;
align-self: flex-start;
.tg-placeholder--secondary {
opacity: 0.8;
}
.no-results {
text-align: center;
padding: 60px 20px;
color: var(--tg-theme-hint-color, #666);
/* Spinner component */
.tg-spinner {
text-align: center;
padding: var(--tg-spacing-xxl);
display: none;
}
.hidden {
display: none !important;
.tg-spinner.tg-spinner--visible {
display: block;
}
.converting {
opacity: 0.6;
pointer-events: none;
.tg-spinner__icon {
width: 32px;
height: 32px;
border: 2px solid var(--tg-color-secondary-bg);
border-top: 2px solid var(--tg-color-button);
border-radius: 50%;
margin: 0 auto var(--tg-spacing-lg);
animation: tg-spin 1s linear infinite;
}
.converting::after {
content: "Converting to MP3...";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: var(--tg-theme-button-color, #007AFF);
color: var(--tg-theme-button-text-color, #fff);
padding: 8px 12px;
border-radius: 6px;
font-size: 0.8rem;
.tg-spinner__text {
font-size: var(--tg-font-size-sm);
color: var(--tg-color-hint);
}
.status-message {
padding: 12px 16px;
margin-bottom: 16px;
border-radius: 8px;
font-size: 0.9rem;
font-weight: 500;
animation: slideIn 0.3s ease-out;
@keyframes tg-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.status-success {
background-color: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
/* List component */
.tg-list {
display: none;
flex-direction: column;
gap: var(--tg-spacing-xs);
}
.status-warning {
background-color: #fff3cd;
border: 1px solid #ffeaa7;
color: #856404;
.tg-list.tg-list--visible {
display: flex;
}
.status-info {
background-color: #d1ecf1;
border: 1px solid #bee5eb;
color: #0c5460;
.tg-list-item {
background: var(--tg-color-section-bg);
border-radius: var(--tg-border-radius);
overflow: hidden;
transition: all 0.2s ease;
cursor: pointer;
user-select: none;
-webkit-tap-highlight-color: transparent;
position: relative;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
.tg-list-item:hover {
background: var(--tg-color-secondary-bg);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.tg-list-item:active {
transform: translateY(0);
background: var(--tg-color-secondary-bg);
}
.tg-list-item__content {
display: flex;
align-items: center;
gap: var(--tg-spacing-md);
padding: var(--tg-spacing-md);
}
.tg-list-item__media {
position: relative;
flex-shrink: 0;
}
.tg-list-item__thumbnail {
width: 80px;
height: 60px;
object-fit: cover;
border-radius: var(--tg-border-radius-small);
background: var(--tg-color-secondary-bg);
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
image-rendering: optimizeQuality;
}
.tg-list-item__duration {
position: absolute;
bottom: 2px;
right: 2px;
background: rgba(0, 0, 0, 0.8);
color: white;
font-size: var(--tg-font-size-xs);
padding: 2px 4px;
border-radius: 4px;
font-weight: 500;
}
.tg-list-item__info {
flex: 1;
min-width: 0;
}
.tg-list-item__title {
font-size: var(--tg-font-size-md);
font-weight: 500;
color: var(--tg-color-text);
line-height: var(--tg-line-height-tight);
margin-bottom: var(--tg-spacing-xs);
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.tg-list-item__subtitle {
font-size: var(--tg-font-size-sm);
color: var(--tg-color-hint);
line-height: var(--tg-line-height-tight);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Converting state */
.tg-list-item--converting {
opacity: 0.6;
pointer-events: none;
}
.tg-list-item--converting::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
border: 2px solid var(--tg-color-secondary-bg);
border-top: 2px solid var(--tg-color-button);
border-radius: 50%;
animation: tg-spin 1s linear infinite;
}
/* Status message */
.tg-status-message {
position: fixed;
top: 80px;
left: 50%;
transform: translateX(-50%);
z-index: 1000;
padding: var(--tg-spacing-md) var(--tg-spacing-lg);
border-radius: var(--tg-border-radius);
font-size: var(--tg-font-size-sm);
font-weight: 500;
animation: tg-slide-in 0.3s ease-out;
display: flex;
align-items: center;
gap: var(--tg-spacing-sm);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
max-width: calc(100vw - 32px);
width: calc(100vw - 64px);
min-width: 300px;
}
.tg-status-message--success {
background: rgba(52, 199, 89, 0.1);
border: 1px solid rgba(52, 199, 89, 0.3);
color: #34c759;
}
.tg-status-message--error {
background: rgba(255, 59, 48, 0.1);
border: 1px solid rgba(255, 59, 48, 0.3);
color: var(--tg-color-destructive);
}
.tg-status-message--info {
background: rgba(0, 122, 255, 0.1);
border: 1px solid rgba(0, 122, 255, 0.3);
color: var(--tg-color-button);
}
@keyframes tg-slide-in {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Utility classes */
.tg-hidden {
display: none !important;
}
.tg-visible {
display: block !important;
}
/* Responsive design */
@media (max-width: 768px) and (min-width: 481px) {
.tg-list-item__thumbnail {
width: 100px;
height: 100px;
}
.tg-list-item__title {
font-size: var(--tg-font-size-sm);
}
}
@media (max-width: 480px) {
.video-item {
flex-direction: column;
}
.video-thumbnail {
width: 100%;
height: 180px;
}
.container {
padding: 16px 12px;
}
.tg-content {
padding: var(--tg-spacing-md);
}
.tg-navigation {
padding: var(--tg-spacing-md);
}
.tg-list {
grid-template-columns: 1fr;
gap: var(--tg-spacing-sm);
}
.tg-list-item__content {
flex-direction: row;
text-align: left;
padding: var(--tg-spacing-sm);
}
.tg-list-item__media {
margin-bottom: 0;
margin-right: var(--tg-spacing-sm);
flex-shrink: 0;
}
.tg-list-item__thumbnail {
width: 60px;
height: 60px;
}
.tg-list-item__info {
flex: 1;
min-width: 0;
}
.tg-list-item__title {
text-align: left;
font-size: var(--tg-font-size-sm);
-webkit-line-clamp: 1;
}
.tg-list-item__subtitle {
text-align: left;
}
}
/* Dark theme support */
@media (prefers-color-scheme: dark) {
:root {
--tg-color-bg: var(--tg-theme-bg-color, #000000);
--tg-color-secondary-bg: var(--tg-theme-secondary-bg-color, #1c1c1e);
--tg-color-section-bg: var(--tg-theme-section-bg-color, #1c1c1e);
--tg-color-text: var(--tg-theme-text-color, #ffffff);
--tg-color-hint: var(--tg-theme-hint-color, #8e8e93);
}
}