hmjz100/LinkSwift · error · Error

错误:<br/>无法提取分享 ID~

Error message

错误:<br/>无法提取分享 ID~

What it means

On the Quark share page, the script tries three ways to derive the share ID (pwd_id): unsafeWindow.factStat.ut.baseParams.pwd_id, factStat.wa.customStatParams.pwd_id, then a regex on location.pathname for /s/<id> or /share/<id>. If all fail it throws this error because subsequent getLink calls require pwd_id. It guards against Quark page-structure changes breaking the extraction.

Source

Thrown at (改)网盘直链下载助手.user.js:8535

				}
				temp.links = [data, {
					isFolder: v => v.file === false,
					getFileName: v => v.file_name,
					getFileSize: v => v.size,
					getFileLink: v => v.download_url,
					convert: {
						aria2: `--header "User-Agent:${config.$quark.api.ua.downloadLink}" --header "Referer:https://${location.host}/" --header "Cookie:${document.cookie}"`,
						curl: `-A "${config.$quark.api.ua.downloadLink}" -e "https://${location.host}/" -b "${document.cookie}"`,
						bitcomet: `user_agent=${encodeURIComponent(config.$quark.api.ua.downloadLink)}&refer=${encodeURIComponent(`https://${location.host}/`)}&cookie=${encodeURIComponent(document.cookie)}`
					},
					tooltip: config.$quark.dom
				}];
				base.showMainDialog(config.base.dom.button[temp.mode].title, base.generateDOM(temp.links), config.base.dom.button[temp.mode].footer);
			} else if (temp.page === "share") {
				const pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || // fast
					unsafeWindow.factStat?.wa?.customStatParams?.pwd_id || // drive
					location.pathname.match(/^\/(?:s|share)\/([a-zA-Z0-9]+)/)?.[1]; // 兜底
				if (!pwd_id) throw new Error("错误:<br/>无法提取分享 ID~");

				const data = [];
				const batchSize = 15;
				let proc = 0;
				selects = selects.filter(item => item.file === true)
				for (let i = 0; i < selects.length; i += batchSize) {
					// 获取当前批次文件
					const batch = selects.slice(i, i + batchSize);
					const fids = batch.map(item => item.fid);
					const fids_token = batch.map(item => item.share_fid_token);
					// 发起请求获取链接
					const res = await base.post(config.$quark.api.getLink, { "fids": fids, "fids_token": fids_token, pwd_id, "stoken": batch[0].stoken }, { "Content-Type": "application/json", "Cookie": String(document.cookie), "User-Agent": config.$quark.api.ua.downloadLink });

					if (!res || res.code !== 0 || !res.data) {
						if (res.code == 31001) throw new Error("提示:<br/>请先登录网盘~<br/>代码:" + res.code);
						if (res.code == 23018) {
							const fid = res.message?.match(/\[([a-f0-9]{32})\]/)?.[1];
							const item = batch.find(item => item.fid === fid);

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Open the share via a canonical https://pan.quark.cn/s/<id> URL and retry
  2. Check window.factStat in the console to see if the globals moved and update the extraction paths
  3. Update the userscript to a version matching the current Quark page structure

Example fix

// before
const pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || location.pathname.match(/^\/(?:s|share)\/([a-zA-Z0-9]+)/)?.[1];
// after
const pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || unsafeWindow.__INITIAL_STATE__?.share?.pwd_id || location.pathname.match(/^\/(?:s|share)\/([a-zA-Z0-9]+)/)?.[1];
Defensive patterns

Strategy: validation

Validate before calling

const pwd_id = location.pathname.match(/^\/(?:s|share)\/([a-zA-Z0-9]+)/)?.[1]; if (!pwd_id) { alert('请在分享页 (pan.quark.cn/s/...) 使用本功能'); return; }

Type guard

function hasPwdId(w){ return !!(w?.factStat?.ut?.baseParams?.pwd_id || w?.factStat?.wa?.customStatParams?.pwd_id); }

Try / catch

try { await exportLinks() } catch (e) { if (String(e.message).includes('无法提取分享 ID')) { location.assign('https://pan.quark.cn/s/' + prompt('粘贴分享ID')); } else throw e; }

Prevention

When it happens

Trigger: Clicking the script's download button on a URL that is neither /s/<id> nor /share/<id>, or Quark removing/renaming the factStat global so both stat-based extractions return undefined.

Common situations: Running the script on the wrong page (home/drive page routed as 'share'); Quark updated its stats SDK breaking factStat; accessing a share via an unusual entry URL or SPA state without a path change.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/15956b0ef80495ce. Report an issue: GitHub.