Flight Simulator Chart Downloader

Adds a download button for flight simulator charts

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Flight Simulator Chart Downloader
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a download button for flight simulator charts
// @author       jtpotato
// @match        https://planner.flightsimulator.com/*
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    // Create and style the download button
    const downloadBtn = document.createElement('button');
    downloadBtn.innerHTML = 'Download Chart';
    downloadBtn.style.position = 'fixed';
    downloadBtn.style.top = '80px';
    downloadBtn.style.right = '80px';
    downloadBtn.style.zIndex = '9999';
    downloadBtn.style.padding = '10px 20px';
    downloadBtn.style.backgroundColor = '#0078d4';
    downloadBtn.style.color = 'white';
    downloadBtn.style.border = 'none';
    downloadBtn.style.borderRadius = '5px';
    downloadBtn.style.cursor = 'pointer';
    downloadBtn.addEventListener('mouseover', () => downloadBtn.style.backgroundColor = '#006cbd');
    downloadBtn.addEventListener('mouseout', () => downloadBtn.style.backgroundColor = '#0078d4');

    // Add click handler
    downloadBtn.addEventListener('click', () => {
        const chartImage = document.getElementById('chart-preview-image');

        if (chartImage && chartImage.src) {
            // Create temporary link to trigger download
            const link = document.createElement('a');
            link.href = chartImage.src;
            link.download = `flight_chart_${Date.now()}.png`;  // Generates unique filename
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        } else {
            alert('Chart image not found!');
        }
    });

    // Add button to the page when DOM is loaded
    // window.addEventListener('DOMContentLoaded', () => {
      console.log("Inserted Button!")
        document.body.appendChild(downloadBtn);
    // });
})();