diff --git a/Mimante/App.xaml b/Mimante/App.xaml index 8a3dd23..7d8487d 100644 --- a/Mimante/App.xaml +++ b/Mimante/App.xaml @@ -4,6 +4,10 @@ xmlns:local="clr-namespace:Mimante" StartupUri="MainWindow.xaml"> - + + + + + diff --git a/Mimante/BrowserWindow.xaml b/Mimante/BrowserWindow.xaml new file mode 100644 index 0000000..a00856d --- /dev/null +++ b/Mimante/BrowserWindow.xaml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mimante/BrowserWindow.xaml.cs b/Mimante/BrowserWindow.xaml.cs new file mode 100644 index 0000000..cb08c2b --- /dev/null +++ b/Mimante/BrowserWindow.xaml.cs @@ -0,0 +1,204 @@ +using System; +using System.Windows; +using System.Windows.Input; +using Microsoft.Web.WebView2.Core; + +namespace AutoBidder +{ + /// + /// Finestra browser separata per navigazione Bidoo + /// + public partial class BrowserWindow : Window + { + public event Action? OnAddAuction; + + public BrowserWindow() + { + InitializeComponent(); + + Loaded += BrowserWindow_Loaded; + } + + private async void BrowserWindow_Loaded(object sender, RoutedEventArgs e) + { + try + { + if (webView.CoreWebView2 == null) + { + await webView.EnsureCoreWebView2Async(); + } + + webView.NavigationCompleted += WebView_NavigationCompleted; + webView.NavigationStarting += WebView_NavigationStarting; + + // Context menu per aggiungere asta + if (webView.CoreWebView2 != null) + { + webView.CoreWebView2.ContextMenuRequested += CoreWebView2_ContextMenuRequested; + webView.CoreWebView2.Navigate("https://it.bidoo.com"); + } + } + catch (Exception ex) + { + MessageBox.Show($"Errore inizializzazione: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private void CoreWebView2_ContextMenuRequested(object? sender, CoreWebView2ContextMenuRequestedEventArgs e) + { + try + { + var currentUrl = webView.CoreWebView2?.Source ?? ""; + + if (IsValidAuctionUrl(currentUrl) && webView.CoreWebView2 != null) + { + // Aggiungi voce menu contestuale + var menuItem = webView.CoreWebView2.Environment.CreateContextMenuItem( + "Aggiungi asta al monitoraggio", + null, + CoreWebView2ContextMenuItemKind.Command); + + menuItem.CustomItemSelected += (s, args) => + { + OnAddAuction?.Invoke(currentUrl); + }; + + e.MenuItems.Insert(0, menuItem); + } + } + catch { } + } + + private void WebView_NavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e) + { + if (!string.IsNullOrEmpty(e.Uri) && !IsBidooUrl(e.Uri)) + { + e.Cancel = true; + MessageBox.Show("Solo domini Bidoo consentiti!", "Navigazione Bloccata", MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + + private void WebView_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e) + { + try + { + Dispatcher.BeginInvoke(() => + { + BackButton.IsEnabled = webView.CoreWebView2?.CanGoBack ?? false; + + var url = webView.CoreWebView2?.Source ?? ""; + if (!string.IsNullOrEmpty(url)) + { + AddressBar.Text = url; + } + }); + } + catch { } + } + + private bool IsBidooUrl(string url) + { + if (string.IsNullOrWhiteSpace(url)) return false; + + try + { + var uri = new Uri(url); + var host = uri.Host.ToLowerInvariant(); + + return host.Contains("bidoo.com") || host.Contains("bidoo.it") || + host.Contains("bidoo.fr") || host.Contains("bidoo.es") || + host.Contains("bidoo.de"); + } + catch + { + return false; + } + } + + private bool IsValidAuctionUrl(string url) + { + if (!IsBidooUrl(url)) return false; + + try + { + var uri = new Uri(url); + return uri.AbsolutePath.Contains("/asta/") || uri.Query.Contains("?a="); + } + catch + { + return false; + } + } + + private void BackButton_Click(object sender, RoutedEventArgs e) + { + webView.CoreWebView2?.GoBack(); + } + + private void RefreshButton_Click(object sender, RoutedEventArgs e) + { + webView.CoreWebView2?.Reload(); + } + + private void NavigateButton_Click(object sender, RoutedEventArgs e) + { + NavigateToAddress(); + } + + private void AddressBar_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Enter) + { + NavigateToAddress(); + } + } + + private void NavigateToAddress() + { + try + { + var url = AddressBar.Text.Trim(); + + if (string.IsNullOrEmpty(url)) return; + + if (!url.StartsWith("http")) + { + url = "https://" + url; + } + + if (!IsBidooUrl(url)) + { + MessageBox.Show("Solo URL Bidoo consentiti!", "URL Non Valido", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + webView.CoreWebView2?.Navigate(url); + } + catch (Exception ex) + { + MessageBox.Show($"Errore navigazione: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private void AddCurrentPageButton_Click(object sender, RoutedEventArgs e) + { + try + { + var currentUrl = webView.CoreWebView2?.Source ?? ""; + + if (string.IsNullOrEmpty(currentUrl) || !IsValidAuctionUrl(currentUrl)) + { + MessageBox.Show("La pagina corrente non � un'asta valida!", "URL Non Valido", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + OnAddAuction?.Invoke(currentUrl); + MessageBox.Show("Asta aggiunta al monitoraggio!", "Successo", MessageBoxButton.OK, MessageBoxImage.Information); + } + catch (Exception ex) + { + MessageBox.Show($"Errore: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + } +} diff --git a/Mimante/Converters/AndNotPausedConverter.cs b/Mimante/Converters/AndNotPausedConverter.cs new file mode 100644 index 0000000..bcf10eb --- /dev/null +++ b/Mimante/Converters/AndNotPausedConverter.cs @@ -0,0 +1,23 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace AutoBidder.Converters +{ + public class AndNotPausedConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2 && values[0] is bool isActive && values[1] is bool isPaused) + { + return isActive && !isPaused; + } + return false; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Mimante/Converters/BoolToOpacityConverter.cs b/Mimante/Converters/BoolToOpacityConverter.cs new file mode 100644 index 0000000..f76ea35 --- /dev/null +++ b/Mimante/Converters/BoolToOpacityConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace AutoBidder.Converters +{ + // Converte bool in Opacity: true -> 0.5 (disabilitato), false -> 1.0 (abilitato) + public class BoolToOpacityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool inverse = parameter?.ToString() == "Inverse"; + if (value is bool b) + { + if (inverse) + return b ? 0.5 : 1.0; + else + return b ? 1.0 : 0.5; + } + return 1.0; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + // Converte (IsActive, IsPaused) in Opacity per il pulsante Pausa + public class PauseButtonOpacityConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2 && values[0] is bool isActive && values[1] is bool isPaused) + { + return (isActive && !isPaused) ? 1.0 : 0.5; + } + return 0.5; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Mimante/Converters/Converters.xaml b/Mimante/Converters/Converters.xaml new file mode 100644 index 0000000..b0a3b67 --- /dev/null +++ b/Mimante/Converters/Converters.xaml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/Mimante/Converters/InverseBoolConverter.cs b/Mimante/Converters/InverseBoolConverter.cs new file mode 100644 index 0000000..1720a21 --- /dev/null +++ b/Mimante/Converters/InverseBoolConverter.cs @@ -0,0 +1,23 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace AutoBidder.Converters +{ + public class InverseBoolConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool b) + return !b; + return true; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool b) + return !b; + return true; + } + } +} diff --git a/Mimante/Converters/StartResumeConverter.cs b/Mimante/Converters/StartResumeConverter.cs new file mode 100644 index 0000000..8ee07e5 --- /dev/null +++ b/Mimante/Converters/StartResumeConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace AutoBidder.Converters +{ + // Returns true when the Start/Resume button for a row should be enabled: + // Enabled when NOT active (stopped) OR when paused (to resume). + public class StartResumeConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length >= 2 && values[0] is bool isActive && values[1] is bool isPaused) + { + return (!isActive) || isPaused; + } + return false; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Mimante/Dialogs/SessionDialogs.cs b/Mimante/Dialogs/SessionDialogs.cs new file mode 100644 index 0000000..fac15f4 --- /dev/null +++ b/Mimante/Dialogs/SessionDialogs.cs @@ -0,0 +1,247 @@ +using System.Windows; +using System.Windows.Controls; + +namespace AutoBidder +{ + /// + /// Dialog per inizializzare sessione Bidoo + /// Richiede: Auth Token + Username + /// + public class SessionDialog : Window + { + private readonly TextBox _tokenTextBox; + private readonly TextBox _usernameTextBox; + + public string AuthToken => _tokenTextBox.Text.Trim(); + public string Username => _usernameTextBox.Text.Trim(); + + public SessionDialog(string existingToken = "", string existingUsername = "") + { + Title = "Configura Sessione Bidoo"; + Width = 680; + Height = 420; + WindowStartupLocation = WindowStartupLocation.CenterOwner; + ResizeMode = ResizeMode.NoResize; + Background = System.Windows.Media.Brushes.Black; + Foreground = System.Windows.Media.Brushes.White; + + var grid = new Grid { Margin = new Thickness(20) }; + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(140) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(15) }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(20) }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + var label1 = new TextBlock + { + Text = "Cookie __stattrb (F12 > Application > Cookies > __stattrb):", + FontWeight = FontWeights.SemiBold, + Foreground = System.Windows.Media.Brushes.White, + TextWrapping = TextWrapping.Wrap + }; + Grid.SetRow(label1, 0); + + _tokenTextBox = new TextBox + { + Text = existingToken, + Padding = new Thickness(10), + TextWrapping = TextWrapping.Wrap, + AcceptsReturn = false, + VerticalScrollBarVisibility = ScrollBarVisibility.Auto, + VerticalContentAlignment = VerticalAlignment.Top, + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(15, 15, 15)), + Foreground = System.Windows.Media.Brushes.LightGray, + FontFamily = new System.Windows.Media.FontFamily("Consolas"), + FontSize = 11, + ToolTip = "Esempio: eyJVU0VSSUQiOiI2NzA3NjY0Ii..." + }; + Grid.SetRow(_tokenTextBox, 2); + + var label2 = new TextBlock + { + Text = "Username Bidoo:", + FontWeight = FontWeights.SemiBold, + Foreground = System.Windows.Media.Brushes.White + }; + Grid.SetRow(label2, 4); + + _usernameTextBox = new TextBox + { + Text = existingUsername, + Padding = new Thickness(10), + FontSize = 14, + VerticalContentAlignment = VerticalAlignment.Center, + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(15, 15, 15)), + Foreground = System.Windows.Media.Brushes.LightGray + }; + Grid.SetRow(_usernameTextBox, 6); + + var buttonPanel = new StackPanel + { + Orientation = Orientation.Horizontal, + HorizontalAlignment = HorizontalAlignment.Right + }; + Grid.SetRow(buttonPanel, 8); + + var okButton = new Button + { + Content = "Conferma", + Width = 120, + Height = 40, + Margin = new Thickness(0, 0, 10, 0), + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 204, 102)), + Foreground = System.Windows.Media.Brushes.White, + FontWeight = FontWeights.Bold, + FontSize = 14 + }; + var cancelButton = new Button + { + Content = "Annulla", + Width = 120, + Height = 40, + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(204, 0, 0)), + Foreground = System.Windows.Media.Brushes.White, + FontWeight = FontWeights.Bold, + FontSize = 14 + }; + + okButton.Click += (s, e) => + { + if (string.IsNullOrWhiteSpace(AuthToken) || string.IsNullOrWhiteSpace(Username)) + { + MessageBox.Show("Inserisci Token e Username!", "Errore", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + DialogResult = true; + Close(); + }; + cancelButton.Click += (s, e) => { DialogResult = false; Close(); }; + + buttonPanel.Children.Add(okButton); + buttonPanel.Children.Add(cancelButton); + + grid.Children.Add(label1); + grid.Children.Add(_tokenTextBox); + grid.Children.Add(label2); + grid.Children.Add(_usernameTextBox); + grid.Children.Add(buttonPanel); + + Content = grid; + + Loaded += (s, e) => _tokenTextBox.Focus(); + } + } + + /// + /// Dialog semplificato per aggiungere asta (ID o URL completo) + /// + public class AddAuctionSimpleDialog : Window + { + private readonly TextBox _auctionIdTextBox; + public string AuctionId => _auctionIdTextBox.Text.Trim(); + + public AddAuctionSimpleDialog() + { + Title = "Aggiungi Asta"; + Width = 680; + Height = 280; + WindowStartupLocation = WindowStartupLocation.CenterOwner; + ResizeMode = ResizeMode.NoResize; + Background = System.Windows.Media.Brushes.Black; + Foreground = System.Windows.Media.Brushes.White; + + var grid = new Grid { Margin = new Thickness(20) }; + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(10) }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(20) }); + grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); + + var label = new TextBlock + { + Text = "URL Asta o ID:", + FontWeight = FontWeights.SemiBold, + Foreground = System.Windows.Media.Brushes.White + }; + Grid.SetRow(label, 0); + + _auctionIdTextBox = new TextBox + { + Text = "", + Padding = new Thickness(10), + FontSize = 13, + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(15, 15, 15)), + Foreground = System.Windows.Media.Brushes.LightGray, + VerticalContentAlignment = VerticalAlignment.Center + }; + Grid.SetRow(_auctionIdTextBox, 2); + + var hintLabel = new TextBlock + { + Text = "Esempio: https://it.bidoo.com/auction.php?a=Galaxy_S25_Ultra_256GB_81204324\nOppure: 81204324", + FontSize = 11, + Foreground = System.Windows.Media.Brushes.Gray, + TextWrapping = TextWrapping.Wrap + }; + Grid.SetRow(hintLabel, 4); + + var buttonPanel = new StackPanel + { + Orientation = Orientation.Horizontal, + HorizontalAlignment = HorizontalAlignment.Right + }; + Grid.SetRow(buttonPanel, 6); + + var okButton = new Button + { + Content = "Aggiungi", + Width = 120, + Height = 40, + Margin = new Thickness(0, 0, 10, 0), + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 204, 102)), + Foreground = System.Windows.Media.Brushes.White, + FontWeight = FontWeights.Bold, + FontSize = 14 + }; + var cancelButton = new Button + { + Content = "Annulla", + Width = 120, + Height = 40, + Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(204, 0, 0)), + Foreground = System.Windows.Media.Brushes.White, + FontWeight = FontWeights.Bold, + FontSize = 14 + }; + + okButton.Click += (s, e) => { DialogResult = true; Close(); }; + cancelButton.Click += (s, e) => { DialogResult = false; Close(); }; + _auctionIdTextBox.KeyDown += (s, e) => + { + if (e.Key == System.Windows.Input.Key.Enter) + { + DialogResult = true; + Close(); + } + }; + + buttonPanel.Children.Add(okButton); + buttonPanel.Children.Add(cancelButton); + + grid.Children.Add(label); + grid.Children.Add(_auctionIdTextBox); + grid.Children.Add(hintLabel); + grid.Children.Add(buttonPanel); + + Content = grid; + + Loaded += (s, e) => _auctionIdTextBox.Focus(); + } + } +} diff --git a/Mimante/MainWindow.xaml b/Mimante/MainWindow.xaml index 722cfb9..38f0853 100644 --- a/Mimante/MainWindow.xaml +++ b/Mimante/MainWindow.xaml @@ -1,609 +1,424 @@ - - - - - - - - - - - - - - + + + + + - - + + + + + + + + + + + - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +