JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
about 4 hours ago3 views
👨‍💻Programming

Untitled Page

// ==UserScript==
// @name         DOWNLOAD BUTTON 2026s (Only Target ID & Specific Year)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Show custom download modal for fixed member ID and fixed year only
// @match        https://passbook.epfindia.gov.in/MemberPassBook/passbook?token*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const targetMemberID = 'PUPUN34708350000010016'; // Fixed member ID
    const allowedYear = '2026'; // Change this to the year you want to allow (string)

    function isTargetMemberSelected() {
        const selectEl = document.getElementById('selectmid');
        return !!selectEl && String((selectEl.value || '').trim()) === targetMemberID;
    }

    function removeExistingModal() {
        const old = document.getElementById('downloadModal');
        if (!old) return;
        try {
            // If Bootstrap instantiated it, hide it first to let bootstrap clean up backdrop
            if (window.bootstrap && bootstrap.Modal) {
                const inst = bootstrap.Modal.getInstance(old);
                if (inst) inst.hide();
            }
        } catch (e) { /* ignore */ }
        // remove nodes if still present
        old.remove();
        const oldBackdrop = document.querySelector('.modal-backdrop');
        if (oldBackdrop) oldBackdrop.remove();
        document.body.classList.remove('modal-open');
    }

    function createModalHTML(year) {
        return `
            <div class="modal fade" id="downloadModal" tabindex="-1" aria-labelledby="downloadModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-body modal-custom-body">
                            <div id="div_pb_dfm">
                                <div class="col-sm-12 modal-custom-header">
                                    Download - [${year}] Passbook Summary
                                    <button type="button" class="btn-close float-end border-text" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="pad-10 custom-download-modal-layout">
                                    <table id="downloadTable" class="table table-bordered table-100">
                                        <thead class="theader">
                                            <tr>
                                                <td class="va-middle1">File Name</td>
                                                <td class="va-middle1 ta-right">Size (KB)</td>
                                                <td class="va-middle1"></td>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="va-middle1">${targetMemberID}_${year}.pdf</td>
                                                <td class="va-middle1 ta-right">152</td>
                                                <td class="va-middle1">
                                                    <button id="downloadPassbook-2026" class="btn btn-sm btn-success pull-right">
                                                        Download File <i class="fa fa-download"></i>
                                                    </button>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>`;
    }

    function showModalWithBootstrap(modalEl, year) {
        // If bootstrap is present, use it and clean up when hidden
        if (window.bootstrap && bootstrap.Modal) {
            const modal = new bootstrap.Modal(modalEl);
            modalEl.addEventListener('hidden.bs.modal', () => removeExistingModal());
            modal.show();
            return modal;
        }
        // Fallback (very lightweight): show modal classes + add backdrop
        modalEl.classList.add('show');
        modalEl.style.display = 'block';
        document.body.classList.add('modal-open');
        const backdrop = document.createElement('div');
        backdrop.className = 'modal-backdrop fade show';
        document.body.appendChild(backdrop);
        // fallback close wiring
        modalEl.querySelectorAll('[data-bs-dismiss="modal"], .btn-close').forEach(btn => {
            btn.addEventListener('click', removeExistingModal);
        });
        backdrop.addEventListener('click', removeExistingModal);
        return { hide: removeExistingModal };
    }

    function openDownloadModal(year) {
        removeExistingModal();
        document.body.insertAdjacentHTML('beforeend', createModalHTML(year));
        const modalEl = document.getElementById('downloadModal');

        // wire download button
        const dlBtn = modalEl.querySelector('#downloadPassbook');
        if (dlBtn) {
            dlBtn.addEventListener('click', (ev) => {
                ev.preventDefault();
                // === place your real download logic here ===
                console.log(`Download clicked for ${targetMemberID}_${year}.pdf`);
                alert(`(Demo) would start download for ${targetMemberID}_${year}.pdf`);
                // close modal after action
                try {
                    if (window.bootstrap && bootstrap.Modal) {
                        const inst = bootstrap.Modal.getInstance(modalEl);
                        if (inst) inst.hide();
                    } else {
                        removeExistingModal();
                    }
                } catch (e) { removeExistingModal(); }
            });
        }

        // wire close buttons so fallback also works
        modalEl.querySelectorAll('[data-bs-dismiss="modal"], .btn-close').forEach(btn => {
            btn.addEventListener('click', removeExistingModal);
        });

        showModalWithBootstrap(modalEl, year);
    }

    // Event delegation for pb-pdf buttons (works for dynamically added buttons too)
    document.addEventListener('click', function (ev) {
        const btn = ev.target.closest('button[name="pb-pdf"][data-download="true"]');
        if (!btn) return;
        ev.preventDefault();

        const year = String(btn.getAttribute('data-year') || '').trim();

        if (!isTargetMemberSelected()) {
           // alert('Download only available for the target member.');
            return;
        }

        if (year !== String(allowedYear)) {
         //   alert(`Download only available for year ${allowedYear}.`);
            return;
        }

        openDownloadModal(year);
    });

    // remove modal when member selection changes
    const selectEl = document.getElementById('selectmid');
    if (selectEl) {
        selectEl.addEventListener('change', () => removeExistingModal());
    }

    // safety: also remove modal when navigating away or page reload
    window.addEventListener('beforeunload', removeExistingModal);

})();
← Back to timeline