灵猴市集Linghou Market

AIbase AI 日报

AIbaseaibase-daily-news

用途 读取 AIbase AI 日报页面中的公开日报或新闻链接,返回标题、链接、日期文本和摘要。适合快速获取最新 AI 日报条目。 执行前提 先打开 https://www.aibase.com/zh/daily。脚本在当前页面 DOM 中读取 .bg-white .grid a[href]、a[href*="/zh/daily/"] 等公开链接,并在 D…

AI日报AI资讯新闻
版本1.0.0
扫描passed
更新2026-06-28
超时30000ms

匹配范围

*://www.aibase.com/*

排除范围

未声明

能力声明

dom.read

代码

源码已展开
1return await (() => {2  const input = typeof params === "object" && params !== null ? params : {};3  const rawLimit = input.limit === undefined ? 10 : Number(input.limit);4 5  if (!Number.isFinite(rawLimit) || rawLimit <= 0) {6    throw new Error("params.limit must be a positive number.");7  }8 9  const limit = Math.min(Math.floor(rawLimit), 50);10  const cleanText = (value) =>11    String(value || "")12      .replace(/\s+/g, " ")13      .replace(/\u00a0/g, " ")14      .trim();15 16  const absoluteUrl = (value) => {17    if (!value) return null;18    try {19      return new URL(value, window.location.href).href;20    } catch (error) {21      return null;22    }23  };24 25  const isDailyUrl = (url) => /\/(?:zh\/)?daily\/\d+/.test(url);26  const itemMap = new Map();27 28  const addItem = (item) => {29    if (!item.url || !item.title) return;30    if (itemMap.has(item.url)) return;31    itemMap.set(item.url, item);32  };33 34  const anchorSelector = '.bg-white .grid a[href], a[href*="/zh/daily/"], a[href*="/daily/"]';35  for (const anchor of Array.from(document.querySelectorAll(anchorSelector))) {36    const url = absoluteUrl(anchor.getAttribute("href"));37    if (!url || !isDailyUrl(url)) continue;38 39    const container =40      anchor.closest("article") ||41      anchor.closest("li") ||42      anchor.closest("[class*='card']") ||43      anchor.closest(".bg-white") ||44      anchor;45    const textBlocks = Array.from(container.querySelectorAll("h1,h2,h3,p,time,span"))46      .map((node) => cleanText(node.textContent))47      .filter(Boolean);48    const title =49      cleanText(anchor.getAttribute("title")) ||50      textBlocks.find((text) => text.length >= 6) ||51      cleanText(anchor.textContent);52    const summary = textBlocks.find((text) => text !== title && text.length >= 12) || null;53    const dateText =54      cleanText(container.querySelector("time")?.textContent) ||55      (cleanText(container.textContent).match(/\d{4}[/-]\d{1,2}[/-]\d{1,2}|\d{1,2}月\d{1,2}日/) || [null])[0];56    const idMatch = url.match(/\/daily\/(\d+)/);57 58    addItem({59      id: idMatch ? idMatch[1] : null,60      title,61      summary,62      url,63      dateText: dateText || null,64      source: "dom",65    });66  }67 68  if (itemMap.size < limit) {69    const scriptText = Array.from(document.scripts)70      .map((script) => script.textContent || "")71      .join("\n");72    const pattern =73      /(?:\\?")Id(?:\\?"):(\d+)[\s\S]{0,500}?(?:\\?")addtime(?:\\?"):(?:\\?")((?:\\.|[^"\\])*)(?:\\?")[\s\S]{0,500}?(?:\\?")title(?:\\?"):(?:\\?")((?:\\.|[^"\\])*)(?:\\?")/g;74    let match;75 76    while ((match = pattern.exec(scriptText)) && itemMap.size < limit) {77      const id = match[1];78      const title = cleanText(match[3].replace(/\\"/g, '"'));79      const dateText = cleanText(match[2]);80      addItem({81        id,82        title,83        summary: null,84        url: absoluteUrl(`/zh/daily/${id}`),85        dateText,86        source: "page-data",87      });88    }89  }90 91  const items = Array.from(itemMap.values()).slice(0, limit);92 93  return {94    limit,95    count: items.length,96    items,97    pageTitle: cleanText(document.title) || null,98    sourceUrl: window.location.href,99  };100})();