#扩展自定义支付规范

- 自定义支付必须是提示词中，明确要求使用[自定义支付]并明确了自定义支付展示规则时才会使用下方文档，否则忽略
- 当使用了自定义支付，默认支付则需要关闭，否则冲突
- version_name 末尾含npy时，关闭默认支付，但接口仍可用，开发者可通过本自定义支付api拉起支付；不含则默认
async function pay_is() {
    const { userInfo } = await chrome.storage.local.get('userInfo');
    if (Math.floor(Date.now()/1000) <= 1760959946 || chrome.i18n.getUILanguage() === 'zh-CN' || (userInfo && userInfo.end_at && userInfo.end_at > Math.floor(Date.now() / 1000))) {
        return true;
    }
	return false;
}


### 5.1：自定义支付_Web，扩展content.js注入到网页的拉起支付代码
#### 原代码：
button.addEventListener("click", () => {pay_ok();});//网页上注入的按钮被点击
#### 自定义支付_Web写法：
function pay_ok() {alert('这是付费后的功能\n这个方法就可以写付费之后的功能');}
function createButton() {// 创建并注入按钮
	const button = document.createElement('button');
	button.textContent = 'button_test_is_pay';//按钮文本，直接引用多语言示例
	button.addEventListener('click', async() => {//网页上注入的按钮被点击
		if (await pay_is()) {// ✅ 判断是会员则
			pay_ok();
		}else{//不是会员则
			chrome.runtime.sendMessage({ action: "OpenPopupPay" });//拉起支付
		}
	});
	document.body.appendChild(button);
}
if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', createButton);} else {createButton();}


### 5.2：自定义支付_Popup，扩展popup页面拉起支付代码
#### 原代码：
document.getElementById('btn').addEventListener('click', async () => {
    const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
    chrome.tabs.sendMessage(tab.id, {action: 'getImages'}, async (images) => {
        let limit = images.length;
        for (let i = 0; i < limit; i++) {chrome.downloads.download({url: images[i], filename: `image_${i+1}.jpg`});}
    });
});
#### 自定义支付_Popup写法：
showVipDialog()方法是你生成的弹窗页面，该页面用于弹窗用户当前并非会员是否充值会员，下方有两个按钮：1[充值会员] -> 2[继续使用免费功能]
document.getElementById('btn').addEventListener('click', async () => {
    const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
    chrome.tabs.sendMessage(tab.id, {action: 'getImages'}, async (images) => {
        let limit = images.length;
        if (!await pay_is()) {//判断不是会员，则
            const choice = await showVipDialog();
            if (choice === '用户点击了升级会员按钮'){
                chrome.runtime.sendMessage({ action: "OpenPopupPay" });//拉起支付
                return; // 拉起支付，不下载
            }limit = 5;//不是会员就将数组数量设置为5，意思是免费下载5次，之后的收费
        }
        for (let i = 0; i < limit; i++) {chrome.downloads.download({url: images[i], filename: `image_${i+1}.jpg`});}
    });
});