@kadaliao/geektime-downloader 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/download.js +20 -5
  2. package/package.json +1 -1
package/download.js CHANGED
@@ -428,9 +428,8 @@ async function sanitizeArticleHtml(page, rawHtml) {
428
428
 
429
429
  const images = template.content ? template.content.querySelectorAll('img') : [];
430
430
  images.forEach(img => {
431
- if (!img.getAttribute('loading')) {
432
- img.setAttribute('loading', 'lazy');
433
- }
431
+ img.setAttribute('loading', 'eager');
432
+ img.setAttribute('decoding', 'sync');
434
433
  img.style.maxWidth = '100%';
435
434
  img.style.height = 'auto';
436
435
  });
@@ -964,6 +963,22 @@ async function downloadArticleSilent(page, article, outputDir, index, total) {
964
963
  if (process.env.DEBUG) {
965
964
  console.log(chalk.gray(`[silent] 已设置页面内容 ${article.id}`));
966
965
  }
966
+ if (process.env.DEBUG) {
967
+ console.log(chalk.gray(`[silent] 等待图片初步加载 ${article.id}`));
968
+ }
969
+ try {
970
+ await page.waitForFunction(() => {
971
+ const imgs = Array.from(document.images || []);
972
+ if (imgs.length === 0) {
973
+ return true;
974
+ }
975
+ return imgs.every(img => img.complete);
976
+ }, { timeout: 30000 });
977
+ } catch (waitError) {
978
+ if (process.env.DEBUG) {
979
+ console.log(chalk.gray(`[silent] 图片初步加载等待超时 ${article.id}: ${waitError?.message || waitError}`));
980
+ }
981
+ }
967
982
  try {
968
983
  await page.waitForLoadState('networkidle', { timeout: 5000 });
969
984
  if (process.env.DEBUG) {
@@ -991,7 +1006,7 @@ async function downloadArticleSilent(page, article, outputDir, index, total) {
991
1006
  resolve();
992
1007
  }
993
1008
  };
994
- const attachTimeout = () => setTimeout(safeResolve, 3000);
1009
+ const attachTimeout = () => setTimeout(safeResolve, 15000);
995
1010
  let fallbackTimer = null;
996
1011
 
997
1012
  // 如果图片还未加载完成,等待加载
@@ -1065,7 +1080,7 @@ async function downloadArticleSilent(page, article, outputDir, index, total) {
1065
1080
  }
1066
1081
 
1067
1082
  // 等待图片处理完成
1068
- await page.waitForTimeout(1000);
1083
+ await page.waitForTimeout(30000);
1069
1084
  if (process.env.DEBUG) {
1070
1085
  console.log(chalk.gray(`[silent] 已准备生成PDF ${article.id}`));
1071
1086
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kadaliao/geektime-downloader",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "极客时间专栏文章批量下载工具 - 支持一键下载整个专栏为PDF或EPUB",
5
5
  "type": "module",
6
6
  "main": "download.js",