// ==UserScript==
// @name icardyou-batch
// @namespace https://github.com/liushidai/icardyou-js
// @version 2025-10-21-1.0
// @description 批量导出为excel、pdf;批量确认
// @author liushidai
// @match https://icardyou.icu/sendpostcard/myPostCard/1*
// @match https://www.icardyou.icu/sendpostcard/myPostCard/1*
// @match https://www.icardyou.com/sendpostcard/myPostCard/1*
// @match https://icardyou.com/sendpostcard/myPostCard/1*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_addElement
// @grant GM_log
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js
// @run-at document-body
// ==/UserScript==
(function () {
'use strict';
GM_log("Hello World");
function addCheckbox() {
// 每行添加多选框
$('tbody tr:not(:first)').each(function () {
var checkbox = $('', {
type: 'checkbox', class: 'row-checkbox'
});
$(this).prepend('
| ').find('td:first').append(checkbox);
});
// 为首行添加全选框并设置点击事件
var allCheckbox = $('', {
type: 'checkbox', id: 'all-checkbox'
});
$('tbody tr:first').prepend(' | ').find('th:first').append(allCheckbox);
// 全选框点击处理
$('#all-checkbox').click(function () {
var isChecked = $(this).is(':checked');
$('.row-checkbox').prop('checked', isChecked);
});
// 行内多选框点击处理
$('.row-checkbox').click(function () {
var allChecked = $('.row-checkbox').length === $('.row-checkbox:checked').length;
$('#all-checkbox').prop('checked', allChecked);
});
}
/**
* 添加导出选项框
*/
function addExportModal() {
if (document.getElementById('exportModal')) return;
// 插入样式
const style = document.createElement('style');
style.textContent = `
#exportModal {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.5);
display: none; /* 👈 默认隐藏!非常重要 */
align-items: center;
justify-content: center;
z-index: 9999;
}
/* 其他样式保持不变 */
#exportModal .modal-content {
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
max-width: 300px;
width: 90%;
}
#exportModal button {
margin: 8px;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
#exportModal #exportExcelBtn {
background: #5cb85c;
color: white;
}
#exportModal #exportPdfBtn {
background: #d9534f;
color: white;
}
#exportModal .close {
position: absolute;
top: 10px;
right: 15px;
font-size: 24px;
cursor: pointer;
color: #999;
}
`;
document.head.appendChild(style);
const modal = document.createElement('div');
modal.id = 'exportModal';
modal.innerHTML = `
`;
document.body.appendChild(modal);
// 关闭逻辑
modal.querySelector('.close').onclick = () => modal.style.display = 'none';
modal.onclick = (e) => {
if (e.target === modal) modal.style.display = 'none';
};
// 按钮逻辑
modal.querySelector('#exportExcelBtn').onclick = () => {
modal.style.display = 'none';
if (window.__selectedRowDatas) {
getAddressAndExportExcel(window.__selectedRowDatas);
window.__selectedRowDatas = null;
}
};
modal.querySelector('#exportPdfBtn').onclick = () => {
modal.style.display = 'none';
if (window.__selectedRowDatas) {
const rowDatas = window.__selectedRowDatas;
const resultArray = [];
let completed = 0;
if (rowDatas.length === 0) {
alert('无数据可导出');
return;
}
rowDatas.forEach(param => {
getAddress(param.id, function (response) {
resultArray.push({
cardType: param.cardType,
no: param.no,
status: param.status,
zip: response.zip || '',
realName: response.realName || '',
address: response.address || ''
});
completed++;
if (completed === rowDatas.length) {
resultArray.sort((a, b) => a.id - b.id);
previewForPrint(resultArray); // 👈 改为调用打印预览
}
});
});
window.__selectedRowDatas = null;
}
};
}
/**
* 添加导出按钮 与 批量确认按钮
*/
function addButton() {
// 选择tbody中的第一行tr元素
var firstRow = $('tbody tr:first');
// 创建按钮元素
var exportExcel = $('