• Copies statistics summary to clipboard

    Generates a human-readable text summary of key statistics and copies it to the system clipboard. This function provides a quick way for users to share their listening statistics without exporting files.

    The formatted summary includes:

    • Header with generation timestamp
    • Overview section with key metrics (tracks, artists, skip rate)
    • Temporal analysis (top listening hours, day distribution)
    • Clean formatting with section headers and separators

    The text format is optimized for readability when pasted into messaging applications, social media, or documentation. All numeric values are appropriately formatted with proper units and precision.

    Parameters

    Returns { success: boolean; message?: string }

    Object containing success status and informational message

    // Copy summary to clipboard for sharing
    const stats = await getStatistics();
    const result = copyStatisticsToClipboard(stats);

    if (result.success) {
    showToast("Statistics copied to clipboard");
    } else {
    showError(result.message);
    }
    export function copyStatisticsToClipboard(statistics: StatisticsData): {
    success: boolean;
    message?: string;
    } {
    try {
    // Create a text summary of the statistics
    const summary = [
    "SPOTIFY SKIP TRACKER STATISTICS SUMMARY",
    "=====================================",
    `Generated: ${new Date().toLocaleString()}`,
    `Last Updated: ${new Date(statistics.lastUpdated).toLocaleString()}`,
    "",
    "OVERVIEW",
    "--------",
    `Total Unique Tracks: ${statistics.totalUniqueTracks}`,
    `Total Unique Artists: ${statistics.totalUniqueArtists}`,
    `Overall Skip Rate: ${(statistics.overallSkipRate * 100).toFixed(2)}%`,
    `Discovery Rate: ${(statistics.discoveryRate * 100).toFixed(2)}%`,
    `Total Listening Time: ${formatDuration(statistics.totalListeningTimeMs)}`,
    `Average Session Duration: ${formatDuration(statistics.avgSessionDurationMs)}`,
    "",
    "TOP LISTENING HOURS",
    "-----------------",
    formatTop5FromArray(
    statistics.hourlyDistribution,
    (i) => `${i}:00-${i + 1}:00`,
    ),
    "",
    "LISTENING BY DAY",
    "---------------",
    formatTop5FromArray(
    statistics.dailyDistribution,
    (i) =>
    [
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    ][i],
    ),
    ].join("\n");

    // Copy to clipboard
    clipboard.writeText(summary);

    return { success: true, message: "Statistics summary copied to clipboard" };
    } catch (error) {
    console.error("Error copying statistics to clipboard:", error);
    return {
    success: false,
    message: `Error copying data: ${error instanceof Error ? error.message : "Unknown error"}`,
    };
    }
    }