Auto Download Excel Files

Automatically download all Excel files after login

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Download Excel Files
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically download all Excel files after login
// @author       YourName
// @match        https://universalmedicalrecord.com/dhanvantari*   // Replace with the actual website domain
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // Define the ranges to automate
    const ranges = [
        { start: 1, end: 200 },
        { start: 201, end: 400 },
        { start: 401, end: 600 },
        // Add more ranges as needed
    ];

    // Function to simulate a click on the "Export to Excel" button
    function downloadExcelFile(range) {
        console.log(`Downloading for range: ${range.start} to ${range.end}`);

        // Find the export button (ExcelDisplay2007)
        const excelButton = document.querySelector('[data-format="ExcelDisplay2007"]');
        if (excelButton) {
            // Simulate the click event
            excelButton.click();
            console.log('Export button clicked');
        } else {
            console.error('Excel export button not found!');
        }
    }

    // Main function to loop through the ranges
    async function downloadAllFiles() {
        for (const range of ranges) {
            console.log(`Processing range: ${range.start}-${range.end}`);

            // Simulate inputting the range (you may need to adjust this)
            const inputField = document.querySelector('input[name="rangeInput"]'); // Replace with the actual input field
            if (inputField) {
                inputField.value = `${range.start}-${range.end}`;
                console.log(`Set input range: ${inputField.value}`);
            } else {
                console.warn('Range input field not found, skipping input!');
            }

            // Trigger the Excel download
            downloadExcelFile(range);

            // Wait for a few seconds to avoid overwhelming the server
            await new Promise(resolve => setTimeout(resolve, 5000)); // Adjust delay as needed
        }

        console.log('All files downloaded!');
    }

    // Run the script when you execute it manually
    console.log('Tampermonkey script loaded. Press Ctrl+Shift+I to check the console.');
    downloadAllFiles();
})();