// ==UserScript==
// @name EPFO Service History Date & Total Service Modifier
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Modifies dates by Member ID and automatically recalculates Total Service duration.
// @author You
// @match https://passbook.epfindia.gov.in/MemberPassBook/service-history*
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
// CONFIGURATION: Map Member IDs to your custom dates
// Format: "DD-Mon-YYYY" (e.g., "01-Jan-2024")
const dateOverrides = {
"TNMAS00313090001723119": {
joining: "01-Jul-2016",
exit: "30-Sep-2016"
},
"PYKRP26032100000010199": {
joining: "01-Nov-2016",
exit: "25-Apr-2022"
}
// Add more Member IDs here as needed:
// "YOUR_MEMBER_ID_HERE": { joining: "DD-Mon-YYYY", exit: "DD-Mon-YYYY" }
};
let isApplyingChanges = false;
// Helper function to calculate duration between two date strings (DD-Mon-YYYY)
function calculateServiceDuration(startDateStr, endDateStr) {
const parseDate = (str) => {
const parts = str.split('-');
if (parts.length !== 3) return null;
const monthsMap = { Jan: 0, Feb: 1, Mar: 2, Apr: 3, May: 4, Jun: 5, Jul: 6, Aug: 7, Sep: 8, Oct: 9, Nov: 10, Dec: 11 };
return new Date(parseInt(parts[2], 10), monthsMap[parts[1]], parseInt(parts[0], 10));
};
const start = parseDate(startDateStr);
const end = parseDate(endDateStr);
if (!start || !end || start > end) return "0 Years 0 Months 0 Days";
let years = end.getFullYear() - start.getFullYear();
let months = end.getMonth() - start.getMonth();
let days = end.getDate() - start.getDate() + 1; // Inclusive of start date
if (days < 0) {
months -= 1;
const prevMonth = new Date(end.getFullYear(), end.getMonth(), 0);
days += prevMonth.getDate();
}
if (months < 0) {
years -= 1;
months += 12;
}
return `${years} Years ${months} Months ${days} Days`;
}
function modifyDatesAndService() {
if (isApplyingChanges) return;
const timelineItems = document.querySelectorAll('.timeline-item');
if (!timelineItems.length) return;
isApplyingChanges = true;
timelineItems.forEach(item => {
if (item.dataset.modified === "true") return;
const pElements = item.querySelectorAll('p');
let targetMemberId = null;
pElements.forEach(p => {
const text = p.textContent.trim();
if (dateOverrides[text]) {
targetMemberId = text;
}
});
if (targetMemberId) {
const overrides = dateOverrides[targetMemberId];
const rows = item.querySelectorAll('.row .row');
let currentJoining = null;
let currentExit = null;
let totalServiceValEl = null;
// First pass: Update dates and capture current values for service calculation
rows.forEach(row => {
const labelEl = row.querySelector('.col-md-4 p');
const valueEl = row.querySelector('.col-md-8 p');
if (labelEl && valueEl) {
const labelText = labelEl.textContent.trim();
if (labelText === 'Joining Date') {
if (overrides.joining) {
valueEl.innerHTML = `${overrides.joining} <span class="fa fa-calendar"></span>`;
}
currentJoining = valueEl.textContent.trim().split(' ')[0];
}
if (labelText === 'Exit Date') {
if (overrides.exit) {
valueEl.innerHTML = `${overrides.exit} <span class="fa fa-calendar"></span>`;
}
currentExit = valueEl.textContent.trim().split(' ')[0];
}
if (labelText === 'Total Service') {
totalServiceValEl = valueEl.querySelector('.border-text') || valueEl;
}
}
});
// Second pass: Recalculate and update Total Service if both dates are present
if (currentJoining && currentExit && totalServiceValEl) {
const newDuration = calculateServiceDuration(currentJoining, currentExit);
totalServiceValEl.textContent = ` ${newDuration} `;
console.log(`[EPFO Modifier] Updated ${targetMemberId} -> Joining: ${currentJoining}, Exit: ${currentExit}, Total: ${newDuration}`);
}
// Mark as processed to prevent infinite loops
item.dataset.modified = "true";
}
});
setTimeout(() => {
isApplyingChanges = false;
}, 50);
}
// Run on load
window.addEventListener('load', modifyDatesAndService);
// Watch for dynamic DOM updates safely with debounce
let timeoutId = null;
const observer = new MutationObserver(() => {
if (isApplyingChanges) return;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
modifyDatesAndService();
}, 200);
});
observer.observe(document.body, { childList: true, subtree: true });
})();2 views