{"record":{"id":"15956b0ef80495ce","repo":"hmjz100/LinkSwift","slug":"br-id","errorCode":null,"errorMessage":"错误：<br/>无法提取分享 ID~","messagePattern":"错误：<br/>无法提取分享 ID~","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":8535,"sourceCode":"\t\t\t\t}\r\n\t\t\t\ttemp.links = [data, {\r\n\t\t\t\t\tisFolder: v => v.file === false,\r\n\t\t\t\t\tgetFileName: v => v.file_name,\r\n\t\t\t\t\tgetFileSize: v => v.size,\r\n\t\t\t\t\tgetFileLink: v => v.download_url,\r\n\t\t\t\t\tconvert: {\r\n\t\t\t\t\t\taria2: `--header \"User-Agent:${config.$quark.api.ua.downloadLink}\" --header \"Referer:https://${location.host}/\" --header \"Cookie:${document.cookie}\"`,\r\n\t\t\t\t\t\tcurl: `-A \"${config.$quark.api.ua.downloadLink}\" -e \"https://${location.host}/\" -b \"${document.cookie}\"`,\r\n\t\t\t\t\t\tbitcomet: `user_agent=${encodeURIComponent(config.$quark.api.ua.downloadLink)}&refer=${encodeURIComponent(`https://${location.host}/`)}&cookie=${encodeURIComponent(document.cookie)}`\r\n\t\t\t\t\t},\r\n\t\t\t\t\ttooltip: config.$quark.dom\r\n\t\t\t\t}];\r\n\t\t\t\tbase.showMainDialog(config.base.dom.button[temp.mode].title, base.generateDOM(temp.links), config.base.dom.button[temp.mode].footer);\r\n\t\t\t} else if (temp.page === \"share\") {\r\n\t\t\t\tconst pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || // fast\r\n\t\t\t\t\tunsafeWindow.factStat?.wa?.customStatParams?.pwd_id || // drive\r\n\t\t\t\t\tlocation.pathname.match(/^\\/(?:s|share)\\/([a-zA-Z0-9]+)/)?.[1]; // 兜底\r\n\t\t\t\tif (!pwd_id) throw new Error(\"错误：<br/>无法提取分享 ID~\");\r\n\r\n\t\t\t\tconst data = [];\r\n\t\t\t\tconst batchSize = 15;\r\n\t\t\t\tlet proc = 0;\r\n\t\t\t\tselects = selects.filter(item => item.file === true)\r\n\t\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\t\t// 获取当前批次文件\r\n\t\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\t\tconst fids = batch.map(item => item.fid);\r\n\t\t\t\t\tconst fids_token = batch.map(item => item.share_fid_token);\r\n\t\t\t\t\t// 发起请求获取链接\r\n\t\t\t\t\tconst 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 });\r\n\r\n\t\t\t\t\tif (!res || res.code !== 0 || !res.data) {\r\n\t\t\t\t\t\tif (res.code == 31001) throw new Error(\"提示：<br/>请先登录网盘~<br/>代码：\" + res.code);\r\n\t\t\t\t\t\tif (res.code == 23018) {\r\n\t\t\t\t\t\t\tconst fid = res.message?.match(/\\[([a-f0-9]{32})\\]/)?.[1];\r\n\t\t\t\t\t\t\tconst item = batch.find(item => item.fid === fid);\r","sourceCodeStart":8517,"sourceCodeEnd":8553,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L8517-L8553","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the share via a canonical https://pan.quark.cn/s/<id> URL and retry","Check window.factStat in the console to see if the globals moved and update the extraction paths","Update the userscript to a version matching the current Quark page structure"],"exampleFix":"// before\nconst pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || location.pathname.match(/^\\/(?:s|share)\\/([a-zA-Z0-9]+)/)?.[1];\n// after\nconst pwd_id = unsafeWindow.factStat?.ut?.baseParams?.pwd_id || unsafeWindow.__INITIAL_STATE__?.share?.pwd_id || location.pathname.match(/^\\/(?:s|share)\\/([a-zA-Z0-9]+)/)?.[1];","handlingStrategy":"validation","validationCode":"const pwd_id = location.pathname.match(/^\\/(?:s|share)\\/([a-zA-Z0-9]+)/)?.[1]; if (!pwd_id) { alert('请在分享页 (pan.quark.cn/s/...) 使用本功能'); return; }","typeGuard":"function hasPwdId(w){ return !!(w?.factStat?.ut?.baseParams?.pwd_id || w?.factStat?.wa?.customStatParams?.pwd_id); }","tryCatchPattern":"try { await exportLinks() } catch (e) { if (String(e.message).includes('无法提取分享 ID')) { location.assign('https://pan.quark.cn/s/' + prompt('粘贴分享ID')); } else throw e; }","preventionTips":["Only run the export from a canonical /s/<id> share URL","Hard-reload the share page so SPA state and stats globals are fresh","Check window.factStat in console after Quark updates","Keep the userscript updated for page-structure changes"],"tags":["userscript","quark-netdisk","url-parsing","dom-scraping"],"backgroundTag":"share-id-extraction-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}