MCPcopy
hub / github.com/ChinaGodMan/UserScripts / fetchJsonData

Function fetchJsonData

missav-explorer/missav-explorer.user.js:471–512  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

469 // 获取指定 JSON 数据的函数
470
471 function fetchJsonData() {
472 const cookies = getAllCookies()
473 //alert(cookies);
474 console.log('Current page cookies:', cookies)
475
476 // 构建 API URL
477 const missAvDomain = window.location.hostname
478 const apiUrl = `https://${missAvDomain}/api/playlists/dfe-057`
479
480 // 发送带有 cookies 的请求
481 GM_xmlhttpRequest({
482 method: 'GET',
483 url: apiUrl,
484 headers: {
485 'Cookie': cookies
486 },
487 onload: function (response) {
488 if (response.status === 200) {
489 try {
490 const jsonResponse = JSON.parse(response.responseText)
491 if (jsonResponse && Array.isArray(jsonResponse.data)) {
492 createReportUI(jsonResponse.data, 500) // 假设每页显示 10 个项目
493
494 // 调用 processUrls 函数处理 URLs
495 } else {
496 console.error('JSON 格式无效')
497 showModal('JSON 格式无效', 2000)
498 }
499 } catch (error) {
500 console.error('Error parsing JSON:', error)
501 showModal('解析错误' + error, 2000)
502 }
503 } else {
504 console.error('Request failed with status:', response.status)
505 showModal('解析错误', 2000)
506 }
507 },
508 onerror: function (error) {
509 showModal('解析错误' + error, 2000)
510 }
511 })
512 }
513
514 function processUrl(url) {
515 // 检查是否包含 `page=` 参数

Callers 1

Calls 3

getAllCookiesFunction · 0.85
createReportUIFunction · 0.85
showModalFunction · 0.85

Tested by

no test coverage detected