Loading...
Loading...
Compare original and translation side by side
$ARGUMENTS$ARGUMENTSnavigate_pagenavigate_pagelist_pagesselect_pagetake_snapshotnavigate_pagenavigate_pagelist_pagesselect_pagetake_snapshotFORMAT"pdf""caj"async () => {
// Wait for page load
await new Promise((r, j) => {
let n = 0;
const c = () => {
if (document.querySelector('.brief h1')) r();
else if (++n > 30) j('timeout');
else setTimeout(c, 500);
};
c();
});
// Captcha check
const cap = document.querySelector('#tcaptcha_transform_dy');
if (cap && cap.getBoundingClientRect().top >= 0) {
return { error: 'captcha', message: 'CNKI 正在显示滑块验证码。请在 Chrome 中手动完成拼图验证。' };
}
const format = "FORMAT"; // "pdf" or "caj"
// Check download links
const pdfLink = document.querySelector('#pdfDown') || document.querySelector('.btn-dlpdf a');
const cajLink = document.querySelector('#cajDown') || document.querySelector('.btn-dlcaj a');
// Check login status
const notLogged = document.querySelector('.downloadlink.icon-notlogged')
|| document.querySelector('[class*="notlogged"]');
if (notLogged) {
return { error: 'not_logged_in', message: '下载需要登录。请先在 Chrome 中登录知网账号。' };
}
const title = document.querySelector('.brief h1')?.innerText?.trim()?.replace(/\s*网络首发\s*$/, '') || '';
if (format === 'pdf' && pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (format === 'caj' && cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
} else if (pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
}
return { error: 'no_download', message: '未找到下载链接', hasPDF: !!pdfLink, hasCAJ: !!cajLink };
}FORMAT"pdf""caj"async () => {
// Wait for page load
await new Promise((r, j) => {
let n = 0;
const c = () => {
if (document.querySelector('.brief h1')) r();
else if (++n > 30) j('timeout');
else setTimeout(c, 500);
};
c();
});
// Captcha check
const cap = document.querySelector('#tcaptcha_transform_dy');
if (cap && cap.getBoundingClientRect().top >= 0) {
return { error: 'captcha', message: 'CNKI 正在显示滑块验证码。请在 Chrome 中手动完成拼图验证。' };
}
const format = "FORMAT"; // "pdf" or "caj"
// Check download links
const pdfLink = document.querySelector('#pdfDown') || document.querySelector('.btn-dlpdf a');
const cajLink = document.querySelector('#cajDown') || document.querySelector('.btn-dlcaj a');
// Check login status
const notLogged = document.querySelector('.downloadlink.icon-notlogged')
|| document.querySelector('[class*="notlogged"]');
if (notLogged) {
return { error: 'not_logged_in', message: '下载需要登录。请先在 Chrome 中登录知网账号。' };
}
const title = document.querySelector('.brief h1')?.innerText?.trim()?.replace(/\s*网络首发\s*$/, '') || '';
if (format === 'pdf' && pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (format === 'caj' && cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
} else if (pdfLink) {
pdfLink.click();
return { status: 'downloading', format: 'PDF', title };
} else if (cajLink) {
cajLink.click();
return { status: 'downloading', format: 'CAJ', title };
}
return { error: 'no_download', message: '未找到下载链接', hasPDF: !!pdfLink, hasCAJ: !!cajLink };
}status: downloadingerror: not_logged_inerror: captchastatus: downloadingerror: not_logged_inerror: captcha| Element | Selector | Notes |
|---|---|---|
| PDF download | | |
| CAJ download | | |
| Download area | | parent |
| Not logged in | | |
| Title | | strip trailing "网络首发" |
| 元素 | 选择器 | 说明 |
|---|---|---|
| PDF下载按钮 | | |
| CAJ下载按钮 | | |
| 下载区域 | | 父级 |
| 未登录状态 | | |
| 论文标题 | | 移除末尾的「网络首发」字样 |
#tcaptcha_transform_dygetBoundingClientRect().top >= 0top >= 0top: -1000000px#tcaptcha_transform_dygetBoundingClientRect().top >= 0top >= 0top: -1000000px