Notes
Notes - notes.io |
const log = (msg, type) => {
var icons = { info: '[INFO]', success: '[OK]', warn: '[WARN]', error: '[ERR]', start: '[START]' };
console.log((icons[type] || '[>]') + ' [Paystub] ' + msg);
};
const sleep = function(ms) {
return new Promise(function(r) { setTimeout(r, ms); });
};
const waitForEl = function(selector, timeout) {
if (!timeout) timeout = 12000;
return new Promise(function(resolve, reject) {
var start = Date.now();
function check() {
var el = document.querySelector(selector);
if (el) return resolve(el);
if (Date.now() - start > timeout) return reject(new Error('Timeout: ' + selector));
setTimeout(check, 300);
}
check();
});
};
const loadScript = function(src) {
return new Promise(function(resolve, reject) {
if (document.querySelector('script[src="' + src + '"]')) return resolve();
var s = document.createElement('script');
s.src = src;
s.onload = resolve;
s.onerror = function() { reject(new Error('Script load failed: ' + src)); };
document.head.appendChild(s);
});
};
// Step 1: Libraries Load
log('Libraries loading...', 'start');
try {
await loadScript('https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js');
await loadScript('https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js');
log('Libraries ready!', 'success');
} catch(e) {
log('Library load fail. Error: ' + e.message, 'error');
return;
}
// Step 2: Rows Collect
var rows = Array.from(document.querySelectorAll('tr[tabindex="0"]'));
if (!rows.length) {
log('Koi rows malia nahi! Page check karo.', 'error');
return;
}
var paystubs = rows.map(function(row) {
var cells = row.querySelectorAll('td');
return {
employeeId: cells[0] ? cells[0].textContent.trim() : 'Unknown',
checkDate: cells[1] ? cells[1].textContent.trim().replace(///g, '-') : 'Unknown',
paycheckId: cells[2] ? cells[2].textContent.trim() : 'Unknown'
};
});
log('Total ' + paystubs.length + ' paystubs malia:', 'info');
paystubs.forEach(function(p, i) {
log((i+1) + '. EmpID: ' + p.employeeId + ' | Date: ' + p.checkDate + ' | Check#: ' + p.paycheckId);
});
// Step 3: One by One Process
for (var i = 0; i < paystubs.length; i++) {
var employeeId = paystubs[i].employeeId;
var checkDate = paystubs[i].checkDate;
var paycheckId = paystubs[i].paycheckId;
log('Processing ' + (i+1) + '/' + paystubs.length + ' => ' + employeeId + ' | ' + checkDate, 'start');
// Row click
var currentRows = document.querySelectorAll('tr[tabindex="0"]');
if (!currentRows[i]) {
log('Row ' + (i+1) + ' mili nahi, skip...', 'warn');
continue;
}
currentRows[i].click();
await sleep(2800);
// Print button wait
try {
await waitForEl('[name="printLink"]');
log('Paystub page open thai gayo', 'success');
} catch(e) {
log('Paystub page not load: ' + e.message, 'error');
var backBtn = document.querySelector('a[href*="adviceList"]');
if (backBtn) { backBtn.click(); await sleep(2000); }
continue;
}
await sleep(500);
// PDF Generate
try {
var jsPDF = window.jspdf.jsPDF;
var contentEl =
document.querySelector('.advice-detail') ||
document.querySelector('.payadvice') ||
document.querySelector('.container') ||
document.querySelector('main') ||
document.body;
log('PDF generate thai rahi che...', 'info');
var canvas = await html2canvas(contentEl, {
scale: 2,
useCORS: true,
allowTaint: true,
backgroundColor: '#ffffff',
logging: false
});
var pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
var pageW = pdf.internal.pageSize.getWidth();
var pageH = pdf.internal.pageSize.getHeight();
var imgH = (canvas.height / canvas.width) * pageW;
var imgData = canvas.toDataURL('image/jpeg', 0.95);
pdf.addImage(imgData, 'JPEG', 0, 0, pageW, imgH);
var remaining = imgH - pageH;
var yOffset = -pageH;
while (remaining > 0) {
pdf.addPage();
pdf.addImage(imgData, 'JPEG', 0, yOffset, pageW, imgH);
yOffset -= pageH;
remaining -= pageH;
}
var filename = 'Paystub_' + employeeId + '_' + checkDate + '_' + paycheckId + '.pdf';
pdf.save(filename);
log('Saved: ' + filename, 'success');
} catch(pdfErr) {
log('PDF save fail: ' + pdfErr.message, 'error');
}
await sleep(1200);
// View other advices click
var viewOtherBtn = document.querySelector('a[href*="adviceList"]');
if (viewOtherBtn) {
viewOtherBtn.click();
log('Homepage back again...', 'info');
await sleep(2500);
} else {
log('View other advices button not found, history back...', 'warn');
window.history.back();
await sleep(2500);
}
}
log('All' + paystubs.length + ' paystubs downloaded!', 'success');
})();
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
