Skills

Cnki Navigate Pages

Navigate CNKI search result pages (next/previous/specific page) or change sort order.

Install

npx skills add cookjohn/cnki-skills --skill cnki-navigate-pages -g -a claude-code -y
Category
Engineering
Updated
8mo ago
License
See repository
Context cost
Lightabout 1,114 tokens
Runs scripts
No, instructions only

What it does

Navigate CNKI search result pages (next/previous/specific page) or change sort order. Use when user wants to see more results or change sorting.

CNKI Results Pagination and Sorting

All operations use a single async evaluate_script, no snapshot or wait_for needed.

Arguments

$ARGUMENTS should be one of:

  • next / previous / page N, pagination
  • sort by date / sort by citations / sort by downloads / sort by relevance / sort by comprehensive, sorting

Pagination (single evaluate_script)

Replace ACTION_HERE with "next", "previous", or "page 3":

async () => {
  const cap = document.querySelector('#tcaptcha_transform_dy');
  if (cap && cap.getBoundingClientRect().top >= 0) return { error: 'captcha' };

  const action = "ACTION_HERE";
  const pageLinks = document.querySelectorAll('.pages a');
  const prevMark = document.querySelector('.countPageMark')?.innerText;

  if (action === 'next') {
    const next = Array.from(pageLinks).find(a => a.innerText.trim() === '下一页');
    if (!next) return { error: 'no_next_page' };
    next.click();
  } else if (action === 'previous') {
    const prev = Array.from(pageLinks).find(a => a.innerText.trim() === '上一页');
    if (!prev) return { error: 'no_previous_page' };
    prev.click();
  } else {
    const num = action.replace(/\D/g, '');
    const target = Array.from(pageLinks).find(a => a.innerText.trim() === num);
    if (!target) return { error: 'page_not_found', available: Array.from(pageLinks).map(a => a.innerText.trim()) };
    target.click();
  }

  // Wait for page change
  await new Promise((r, j) => {
    let n = 0;
    const c = () => {
      const mark = document.querySelector('.countPageMark')?.innerText;
      if (mark && mark !== prevMark) r();
      else if (++n > 30) j('timeout');
      else setTimeout(c, 500);
    };
    setTimeout(c, 1000);
  });

  const cap2 = document.querySelector('#tcaptcha_transform_dy');
  if (cap2 && cap2.getBoundingClientRect().top >= 0) return { error: 'captcha' };
Read the whole SKILL.md on GitHub

More in Engineering