匹配范围
*://*.v2ex.com/*v2ex-hot-topicsV2EX 热门话题 用途 读取 V2EX 当前热门话题列表,返回话题标题、节点、回复数和链接。 执行前提 在 V2EX 页面执行即可,无需登录。脚本会请求 V2EX 公开话题接口,网络异常或接口结构变化时会返回执行错误。 参数 limit:可选,返回数量,正整数,默认 20。 返回值 返回数组,每项包含: id:话题 ID。 rank:当前结果中的排序序号…
*://*.v2ex.com/*dom.read1const input = params && typeof params === 'object' ? params : {};2 3function positiveInt(value, fallback) {4 const raw = value === undefined || value === null || value === '' ? fallback : value;5 const number = Number(raw);6 if (!Number.isInteger(number) || number <= 0) {7 throw new Error('limit must be a positive integer');8 }9 return number;10}11 12const limit = positiveInt(input.limit, 20);13const response = await fetch('https://www.v2ex.com/api/topics/hot.json', {14 credentials: 'omit',15 headers: { Accept: 'application/json' },16});17 18if (!response.ok) {19 throw new Error(`V2EX hot topics request failed: HTTP ${response.status}`);20}21 22const data = await response.json();23if (!Array.isArray(data)) {24 throw new Error('V2EX hot topics response shape changed');25}26 27return data.slice(0, limit).map((item, index) => ({28 id: item && item.id != null ? item.id : null,29 rank: index + 1,30 title: item && item.title ? String(item.title) : '',31 node: item && item.node && item.node.title ? String(item.node.title) : '',32 replies: item && item.replies != null ? Number(item.replies) : 0,33 url: item && item.url ? String(item.url) : '',34}));